Fjoergyn
Fjoergyn

Reputation: 13

npm 'module not found', but everything seems to be set up correct

it seems my node_modules folder is being ignored. When I add new modules via 'npm install' the get installed correctly, but trying to import them results in a 'module not found' error. I can even delete the whole 'node_modules' folder and the app is still working.

I've installed some modules globally but I can't import them as well. It worked fine a couple a weeks ago, but now every change I do to the folder is being ignored...

npm: 5.5.1
node: 6.11.3
npm prefix: path/to/my/project
npm prefix -g: /usr/local
npm list --depth=0: returns my installed modules
npm install: installs the modules correctly into the 'node_modules' folder

Other technology used: React, JSX, Babel

I"m importing via import _ from 'lodash';

Any idea what's going on? I tried to solve the problem for two days now...

Examples:

npm install react-pdf --save

installs correctly into the node_modules folder and shows up under 'npm list --depth=0' but trying to import it results in:

Failed to compile.

Error in ./src/components/ProductSearch.js
Module not found: 'react-pdf' in /node/src/components

 @ ./src/components/ProductSearch.js 32:16-36

Updating react to 16.0.0 works well, I end up with 16.0.0 in my 'node_modules' folder but the app is still using 15.3.2

Upvotes: 0

Views: 2449

Answers (2)

stesel
stesel

Reputation: 37

If there in project is used webpack.config.js, might moduleDirectories: ['node_modules'] could help with that:

resolve: {
  root: path.resolve('./src'),
  extensions: ['', '.js'],
  moduleDirectories: ['node_modules']
}

Upvotes: 0

Fjoergyn
Fjoergyn

Reputation: 13

It was a Docker issue. The image did't update correctly. It worked when using 'npm start'.

I needed to re-build the docker image...

Upvotes: 1

Related Questions