Issue: Unable to locate the 'stream/web' module while attempting to execute 'npm start' for a Next.js application, even though the Node version is correct

When I attempted to set up a new application using npm create next-app --typescript, everything seemed to be going smoothly. However, upon trying to start the project with npm start, an error message popped up stating "Error: Cannot find module 'stream/web'." Here's the process I went through:

(base) ➜  Next-Project npm create next-app --typescript
Need to install the following packages:
create-next-app
Ok to proceed? (y) y
✔ What is your project named? … my-app
✔ Would you like to use TypeScript? … No / Yes
✔ Would you like to use ESLint? … No / Yes
✔ Would you like to use Tailwind CSS? … No / Yes
✔ Would you like to use `src/` directory? … No / Yes
✔ Would you like to use App Router? (recommended) … No / Yes
✔ Would you like to customize the default import alias? … No / Yes
Creating a new Next.js app in /Users/tempuser/Documents/React/Next-Project/my-app.

Using npm.

Initializing project with template: app 

Installing dependencies:
- react
- react-dom
- next

npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE package: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="204e4558546011130e140e1119">[email protected]</a>',
npm WARN EBADENGINE required: { node: '>=16.8.0' },
npm WARN EBADENGINE current: { node: 'v15.14.0', npm: '7.24.2' }
npm WARN EBADENGINE }

added 23 packages, and audited 24 packages in 3s

4 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities
Initialized a git repository.

Success! Created my-app at /Users/tempuser/Documents/React/Next-Project/my-app

(base) ➜  Next-Project ls
my-app
(base) ➜  Next-Project cd my-app 
(base) ➜  my-app git:(main) npm start

> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="08657125697878483826392638">[email protected]</a> start
> next start

node:internal/modules/cjs/loader:927
throw err;
^

Error: Cannot find module 'stream/web'
Require stack:
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/node-polyfill-web-streams.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/render.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/lib/server-ipc/index.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/lib/router-server.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/lib/start-server.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/cli/next-start.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/lib/commands.js
- /Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/bin/next
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)
at Function.Module._load (node:internal/modules/cjs/loader:769:27)
at Module.require (node:internal/modules/cjs/loader:996:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/node-polyfill-web-streams.js:6:9)
at Module._compile (node:internal/modules/cjs/loader:1092:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
at Module.load (node:internal/modules/cjs/loader:972:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:996:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/node-polyfill-web-streams.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/render.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/lib/server-ipc/index.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/lib/router-server.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/server/lib/start-server.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/cli/next-start.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/lib/commands.js',
'/Users/tempuser/Documents/React/Next-Project/my-app/node_modules/next/dist/bin/next'
]
}

Upon reviewing the installation information for next-app, it indicated that my current node version was 'v15.14.0' as shown by this line:

npm WARN EBADENGINE   current: { node: 'v15.14.0', npm: '7.24.2' 
However, when checking my node version using nvm ls and node --version, both displayed v18.17.1:

(base) ➜  Next-Project nvm ls
        v18.2.0
->     v18.17.1
         system
default -> node (-> v18.17.1)
node -> stable (-> v18.17.1) (default)
stable -> 18.17 (-> v18.17.1) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/hydrogen (-> v18.17.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.17.1
(base) ➜  Next-Project node --version
npm --version
v18.17.1
10.0.0

Any idea what might have caused this issue? Your insights would be greatly appreciated.

In an attempt to rectify the problem, I experimented with upgrading and downgrading both the node and npm versions in order to ensure compatibility. After each adjustment, I made a point to remove and reinstall the node_modules and package-lock.json files before relaunching the application. It seems to me that the underlying issue may stem from a version mismatch.

Answer №1

Upon investigation, I have found that the next function requires a node engine with a minimum version of 16.4 or higher.

To resolve this issue, I recommend upgrading your node version. Best regards

---- // ----

I personally experienced this issue and was able to solve it by:

Updating to version 16.4

Updating to version >18

Answer №2

Currently facing a similar issue with my next.js and electron application. I was able to resolve it by taking the following steps:

npm install electron@latest

Answer №3

To solve the problem, I deleted the package.json file that was mistakenly installed in a different directory (specifically at the root directory ~) some time ago.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you explain the term used to describe when specific sections of the source code are run during the build process to improve optimization?

One interesting feature I've noticed in next.js is its automatic code optimization during the build process. This means that instead of running the code every time the app is executed, it's evaluated and executed only once during the build. For ...

Nextjs: Issues with Dropdown functionality when using group and group-focus with TailwindCSS

My goal is to make an array visible once a button is clicked. By default, the array should be invisible, similar to drop-down menus in menu bars. I am utilizing the group and group-focus classes. While the array disappears as expected, it does not reappear ...

Adding a new value to an array of objects without altering the existing values in ReactJS and NextJS

I have a JSON file containing image names that I need to organize into a Key-Value Object. I am currently using regex to create keys by removing "-img[image No]". However, I am having trouble storing all the image names in the array without overwriting pre ...

Having trouble with Firebase admin in your Next.js/Stripe webhook integration?

I've encountered an issue when using the stripe webhook in Next.js. Every time I attempt to set it up, I receive the following error: unable to detect a project id in this environment I initially tried setting it up in the app router and then trans ...

Encountering an error while trying to run the command "npm run start" due to an issue of "EMFILE

After running npm update, my project start broke. When I try to use npm run start, it returns the following error: 10% building 0/1 entries 0/0 dependencies 0/0 modulesnode:internal/errors:484 ErrorCaptureStackTrace(err); ^ Error: EMFILE: too many ...

The react-xml-parser package is asking for Babel version "^7.0.0-0", however it was instead loaded with version "6.26.3". I have already attempted all available solutions to resolve this issue

I have attempted numerous solutions from the Github community regarding this issue, but unfortunately none have worked for me. /node_modules/react-xml-parser/dist/bundle.js: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you ha ...

What is the process for obtaining documents that contain arrays with duplicate elements in them?

Looking at my MongoDB documents below, I have identified a pattern: { _id: ObjectId('09de14821345dda65c471c99'), items: [ _id: ObjectId('34de64871345dfa655471c99'), _id: ObjectId('34de64871345dfa655471c91&apo ...

Having trouble installing "npm install react-youtube"? (ERROR)

When attempting to install "react-youtube" using the command "npm install react-youtube," I encountered various errors. Unfortunately, I am unsure of their origin or how to resolve them. Could someone please provide guidance on resolving these installatio ...

How can I prevent writeFileSync from replacing existing data?

When I use this line of code, it deletes all existing data. Is there a method or function that will append the new data on a new line instead? fs.writeFileSync(path.resolve(__dirname, 'quotes.json'), JSON.stringify(quotey)); ...

Employ the next-intl library in a non-react component scenario

Is there a way to utilize next-intl outside of a React component? Currently, I am obtaining the t by utilizing the hook useTranslations, and then passing its instance to my function: function formatFoo(t, foo) { if .... t('bar'); } ...

"Efficient Email Processing: Streamlining Transactions and Bulk Communications

What are the most effective strategies for utilizing both transactional and marketing email? Currently, I am exploring Mailgun for transactional emails because of their free API that aligns with my needs. As my usage grows, they offer affordable pricing p ...

Utilizing node.js and sockets in my backbone application: a comprehensive guide

I have a question that I believe is fairly simple to answer. My node.js server is installed at /usr/local/bin/node The index.html and server.js files are located at /usr/local/bin When I run node, everything works fine. I have a chat application runni ...

Alert in the npm configuration concerning the most recent update

I am currently using an email address at [email protected] and I keep encountering a warning every time I execute any npm command. npm WARN config init.author.email Use `--init-author-email` instead. npm WARN config init.author.name Use `--init-author ...

Having trouble getting the Sass module to install on gulp.js with node.js

Every time I try to run npm install gulp-sass --save-dev, I encounter the same error: gyp ERR! build error gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe` failed with exit code: 1 gyp ERR! stack at ...

When utilizing multer for handling multipart data, hasOwnProperty appears to become undefined

Below is the code snippet I am currently working with: var express = require('express'); var mongoose = require('mongoose'); var bodyParser = require('body-parser'); var multer = require('multer'); var user = requir ...

My server keeps crashing due to an Express.js API call

I'm completely new to express.js and API calls, and I'm stuck trying to figure out why my server keeps crashing. It works fine the first time, rendering the page successfully, but then crashes with the error: TypeError: Cannot read property &apo ...

Enhance Your Angular Experience with Console Extensions

Is there a way to include my custom schematics from npm into the Angular Console's list of available extensions? https://i.stack.imgur.com/HDuAi.png ...

Facing an issue with importing types in Prisma database seeding using TypeScript with the `type:module` configuration

I am currently learning about Prisma and following this tutorial: https://www.prisma.io/blog/fullstack-nextjs-graphql-prisma-oklidw1rhw However, I encountered an issue with the following step: npx prisma db seed --preview-feature Even though I copied the ...

SequelizeEagerLoadingError: There is no association between the model and the otherModel

I've come across this issue several times on various forums but haven't been able to resolve it yet. My setup involves Express and PostgreSQL with Sequelize ORM. The problem lies in the one-to-one relationship between two models: Campus and Acad ...

Issue with deploying production build in Next.js causing 404 errors on sub pages

After deploying my Next.js build code to production using the command next export -o outDir, I noticed that only the home page is working. When attempting to access /login, I am receiving a 404 error. Can anyone offer guidance on how to resolve this issu ...