Node: Node 9.10.0+ strange dependency issue

Created on 13 Apr 2018  路  28Comments  路  Source: nodejs/node

  • Version: v9.11.1
  • Platform: Darwin MBP 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64
  • Subsystem: Apple macOS 10.13.4

It seems Node installation from Homebrew has a strange dependency issue with common stack trace:

internal/modules/cjs/loader.js:550
    throw err;
    ^

Error: Cannot find module '***'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
    at Function.Module._load (internal/modules/cjs/loader.js:475:25)
    at Module.require (internal/modules/cjs/loader.js:598:17)
    at require (internal/modules/cjs/helpers.js:11:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:92:3)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)

Here are related issues:

wrong repo

Most helpful comment

switching to yarn solves the issue for me.

I tried downgrading as far as node v6 and npm@3 but still same issue.
Using yarn install to get dependencies instead of npm install seems to consistently work.

Therefore I think it is actually an issue with npm. The module(s) I am experiencing the issue with are file-loader and url-loader. When installed via npm some of the files are not installed, hence the "Cannot find module". Using yarn all the dependency files are installed as expected.

All 28 comments

weex-toolkit

That dependecy is not a part of Node.js and does not seem to be a part of npm distribution.

@ChALkeR sure, but all this issues happened in last week and have similar stacktrace. It seems the main reason is Homebrew Node installation.

@k06a is there any indication this is a bug with Node though? One of those issues points at this gist https://gist.github.com/DanHerbert/9520689 and homebrew is kind of its own thing, if there are bugs then their repo seems like the place?

@apapirovski this gist is from 2014, it is not actual anymore. Can't find Node Homebrew formula repo.

@k06a there's a comment there re: v9.11.1 so it seems plenty current.

Either way, this doesn't seem to be a Node.js issue but either homebrew or npm which both have their own issue trackers.

I'm going to close this out since there's no indication we can do anything about it.

@apapirovski what is cjs? I can't found it as sub-dependency and it uninstalling helps.

@apapirovski I installed node with nvm and still have the same problem

same for me with homebrew, nodejs 9.11.1, yarn 1.6.0

The same error occurred for me whenever I tried to run "npm install [anything]".

internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module '../lib/utils/unsupported.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:19:21
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:145:3)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)

This is the second time I've run across this error. The first time I completely uninstalled node since it was such a weird issue (see Stack Overflow steps), and then reinstalled with "brew install node", and the command "npm" worked again, along with command "node" which was already working previously.

Now, after a few months, I encounter this error again. I did the same steps to get "npm" working again.

My node and npm versions are as of now: v10.3.0 and 6.1.0

I am also noticing this issue while running certain npm scripts
[email protected] and [email protected]
Error: Cannot find module 'file-loader' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15) at Function.resolve (internal/modules/cjs/helpers.js:30:19)

i'm having the same issue, and if I found out that if I copied out npm folder from global to the project's node module, it will solve it.

switching to yarn solves the issue for me.

I tried downgrading as far as node v6 and npm@3 but still same issue.
Using yarn install to get dependencies instead of npm install seems to consistently work.

Therefore I think it is actually an issue with npm. The module(s) I am experiencing the issue with are file-loader and url-loader. When installed via npm some of the files are not installed, hence the "Cannot find module". Using yarn all the dependency files are installed as expected.

I am getting the following error on node v10.5.0 npm v6.1.0 from inside mongoose v4.11.13. I have been having weird issues with mongoose 5 as well but running fine on a local install for both versions. I will try yarn and see if that helps.

Error: Cannot find module './types/embedded'
     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)

[email protected] build C:\Work\Test 1
webpack-dev-server --config webpack/webpack.config.js

The CLI moved into a separate package: webpack-cli.
Please install 'webpack-cli' in addition to webpack itself to use the CLI.
-> When using npm: npm install webpack-cli -D
-> When using yarn: yarn add webpack-cli -D
internal/modules/cjs/loader.js:596
throw err;
^

Error: Cannot find module 'webpack-cli/bin/config-yargs'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (C:\Work\Test 1node_moduleswebpack-dev-server\binwebpack-dev-server.js:65:1)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: webpack-dev-server --config webpack/webpack.config.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\PLAP07\AppData\Roamingnpm-cache_logs\2018-07-16T14_27_06_982Z-debug.log

Hi friends,
May i know why is the error occurs while running the node mongoHash.js file running the command.
Found many times this process of internal error.Help me to recover this error

internal/modules/cjs/loader.js:596
throw err;
^
Error: Cannot find module 'command-line-args'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
at Function.Module._load (internal/modules/cjs/loader.js:520:25)
at Module.require (internal/modules/cjs/loader.js:650:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (/home/chainflux/Documents/mongoblock-proof-master/mongoHash.js:22:25)
at Module._compile (internal/modules/cjs/loader.js:702:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
at Module.load (internal/modules/cjs/loader.js:612:32)
at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
at Function.Module._load (internal/modules/cjs/loader.js:543:3)

Thanks in advance,
my friends...

I'm on Fedora 28 and I encountered the same problem after 'dnf install nodejs'.
I'm trying to install all the dependencies through dnf but obviously this shouldn't be the solution.

Really appreciated if it could be solved.

I also encountered the same problem. Updating node to v10.9.0 didn't work. Isn't there is a better way than reinstalling node?

I'm also having the same problem. Typically downgrading both node and npm fixes the problem, but there has to be a better solution...

i am having same issue when running npm start.
node version is 10.10.0
npm version is 6.4.1

can someone tell me how to fix it and if downgrading needed then to which version?

I figured out a work around. The problem is caused by a dependency issue in npm, (one of the packages held by the package maintainers is broken). Solution: Install yarn. enter yarn install in your terminal (instead of npm install), you might see a warning about the dangers of using multiple package managers, you can safely ignore this warning. Proceed with the install, and then try entering npm start again in your terminal.

hey,

i tried to execute npm install http-server which i have seen somewhere to give a try,
when i do so i got error

File exists: /home/susaj/susaj/tabcon/proj-tabcon/TabconWeb/node_modules/.bin/hs
and tells to remove the file

same shown for http-server file also, so i removed folowing files

/node_modules/.bin/http-server

/node_modules/.bin/hs

then npm install http-server
everything works good. :)

take a look in here https://github.com/indexzero/http-server/issues/34

Just reinstall NodeJs from site https://nodejs.org/en/

Here is how it got fixed for me but I have no idea why/how. I just got a new computer and downloaded node and yarn but not used either and was getting this error for EVERY node file. So here is what I did.

Instead of typing "node server.js" in terminal prompt, I just typed "yarn" and hit enter.
Let yarn download all its dependencies and yarn.lock file. I then deleted yarn.lock file.
and entered "node server.js" in terminal and voila - it worked!

hey,

i tried to execute npm install http-server which i have seen somewhere to give a try,
when i do so i got error

File exists: /home/susaj/susaj/tabcon/proj-tabcon/TabconWeb/node_modules/.bin/hs
and tells to remove the file

same shown for http-server file also, so i removed folowing files

/node_modules/.bin/http-server

/node_modules/.bin/hs

then npm install http-server
everything works good. :)

take a look in here indexzero/http-server#34

You saved me!! Thanks a lot (Trying install with brew on mac os high sierra FYI)

Solution:
brew uninstall node

download LTS .pkg from nodejs.org and install

Problem solved!

I was using brew and it installed 11.12 which has a bug with cjs. I followed @venom90 advice and downloaded latest from the official site. https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V11.md#11.13.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

akdor1154 picture akdor1154  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

Brekmister picture Brekmister  路  3Comments

addaleax picture addaleax  路  3Comments