npm 'module not found',但一切似乎都设置正确
npm 'module not found', but everything seems to be set up correct
我的 node_modules 文件夹似乎被忽略了。当我通过 'npm install' 添加新模块时,get 安装正确,但尝试导入它们会导致 'module not found' 错误。我什至可以 删除 整个“node_modules”文件夹并且 应用程序仍在运行 .
我已经全局安装了一些模块,但我也无法导入它们。几周前它运行良好,但现在我对文件夹所做的每项更改都被忽略了...
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
使用的其他技术:React、JSX、Babel
我正在通过 import _ from 'lodash';
导入
知道发生了什么事吗?我试了两天才解决这个问题...
例子:
npm install react-pdf --save
正确安装到 node_modules 文件夹并显示在 'npm list --depth=0' 下,但尝试导入它会导致:
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
更新 React 到 16.0.0 效果很好,我最终在我的 'node_modules' 文件夹中得到了 16.0.0,但应用程序仍在使用 15.3.2
如果在项目中使用 webpack.config.js,moduleDirectories: ['node_modules']
可能会有所帮助:
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js'],
moduleDirectories: ['node_modules']
}
这是一个 Docker 问题。图片没有正确更新。使用 'npm start'.
时有效
我需要重新构建 docker 图像...
我的 node_modules 文件夹似乎被忽略了。当我通过 'npm install' 添加新模块时,get 安装正确,但尝试导入它们会导致 'module not found' 错误。我什至可以 删除 整个“node_modules”文件夹并且 应用程序仍在运行 .
我已经全局安装了一些模块,但我也无法导入它们。几周前它运行良好,但现在我对文件夹所做的每项更改都被忽略了...
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
使用的其他技术:React、JSX、Babel
我正在通过 import _ from 'lodash';
知道发生了什么事吗?我试了两天才解决这个问题...
例子:
npm install react-pdf --save
正确安装到 node_modules 文件夹并显示在 'npm list --depth=0' 下,但尝试导入它会导致:
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
更新 React 到 16.0.0 效果很好,我最终在我的 'node_modules' 文件夹中得到了 16.0.0,但应用程序仍在使用 15.3.2
如果在项目中使用 webpack.config.js,moduleDirectories: ['node_modules']
可能会有所帮助:
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js'],
moduleDirectories: ['node_modules']
}
这是一个 Docker 问题。图片没有正确更新。使用 'npm start'.
时有效我需要重新构建 docker 图像...