我的项目最近开始抱怨说,当我运行npm run dev脚本时,它无法解决响应: 跨环境NODE_ENV =开发node_modules / webpack / bin / webpack.js --progress --hide-modules --config = node_modules / laravel-mix / setup / webpack.config.js
npm似乎找不到node_modules目录?
它在Windows机器上可以正常运行,但是当我将其上传到Ubuntu服务器时,出现错误。 我尝试了各种操作,例如删除node_modules和锁定文件,清理npm缓存,检查$ NODE_PATH,重新安装nodejs和npm无济于事。 我不知道这是路径问题还是服务器上缺少什么或什么。
如果您有任何提示,我将不胜感激。
我的package.json:
{
"private": true,
"name": "Write.nogetdigitalt.dk",
"version": "0.0.1",
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "npm run development -- --watch",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"@fortawesome/react-fontawesome": "^0.1.3",
"axios": "^0.18",
"babel-preset-react": "^6.24.1",
"bootstrap": "^4.0.0",
"cross-env": "^5.1",
"jquery": "^3.2",
"laravel-mix": "^2.0",
"lodash": "^4.17.5",
"moment": "^2.23.0",
"popper.js": "^1.12",
"react": "^16.5.2",
"react-datepicker": "^2.0.0",
"react-dom": "^16.5.2",
"redux": "^4.0.1",
"vue": "^2.5.7"
},
"dependencies": {
"@fortawesome/free-solid-svg-icons": "^5.5.0",
"react-icons": "^3.2.0"
}
}
webpack.mix.js
const mix = require('laravel-mix');
const webpack = require('webpack');
mix.webpackConfig({
resolve: {
extensions: ['.js', 'jsx'],
alias: {
'react': 'React'
}
},
plugins: [
new webpack.ProvidePlugin({
'React': 'react',
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
})
]
})
.disableNotifications()
.react('resources/js/app.js', 'public/js')
.sourceMaps()
.sass('resources/sass/app.scss', 'public/css');
错误消息:
ERROR in ./resources/js/pages/Note/Note.js
Module not found: Error: Can't resolve 'react' in '/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note'
resolve 'react' in '/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note'
Parsed request is a module
using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
aliased with mapping 'react': 'React' to 'React'
Parsed request is a module
using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
Field 'browser' doesn't contain a valid alias configuration
after using description file: /var/www/html/write.nogetdigitalt.dk/package.json (relative path: ./resources/js/pages/Note)
resolve as module
/var/www/html/write.nogetdigitalt.dk/resources/js/pages/Note/node_modules doesn't exist or is not a directory
/var/www/html/write.nogetdigitalt.dk/resources/js/pages/node_modules doesn't exist or is not a directory
/var/www/html/write.nogetdigitalt.dk/resources/js/node_modules doesn't exist or is not a directory
/var/www/html/write.nogetdigitalt.dk/resources/node_modules doesn't exist or is not a directory
/var/www/html/node_modules doesn't exist or is not a directory
/var/www/node_modules doesn't exist or is not a directory
/var/node_modules doesn't exist or is not a directory
/node_modules doesn't exist or is not a directory
答案 0 :(得分:0)
您尚未安装软件包依赖项。
npm install
执行该节点模块目录后,即已创建。 并启动您的应用程序。
npm run developement
答案 1 :(得分:0)
对于其他遇到这种问题的人,最好使用NodeJS中的path
来实现不同操作系统之间的路径定义
`const path = require('path');
[...]
resolve: {
extensions: ['.js', 'jsx'],
alias: {
'react': path.resolve(__dirname, 'Path to your folder to alias')
}
}`