Reactjs 网页包缺少模块错误:找不到模块&引用;
我最近从react应用程序中删除了node_modules文件夹,并使用以下package.json运行了npm安装:Reactjs 网页包缺少模块错误:找不到模块&引用;,reactjs,npm,webpack,Reactjs,Npm,Webpack,我最近从react应用程序中删除了node_modules文件夹,并使用以下package.json运行了npm安装: { "name": "test-react-app", "version": "1.0.0", "private": true, "description": "test", "main": "src/index.js", "dependencies": { "body-parser": "^1.18.2", "express": "^4
{
"name": "test-react-app",
"version": "1.0.0",
"private": true,
"description": "test",
"main": "src/index.js",
"dependencies": {
"body-parser": "^1.18.2",
"express": "^4.16.2",
"material-ui": "^0.19.4",
"node-sass-chokidar": "0.0.3",
"npm-run-all": "^4.1.1",
"react": "^15.6.2",
"react-dom": "^15.6.2",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "^1.0.10"
},
"scripts": {
"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
"start-js": "react-scripts start",
"start": "npm-run-all -p watch-css start-js",
"build": "npm run build-css && react-scripts build webpack -p",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"devDependencies": {
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"babel-core": "6.17.0",
"babel-loader": "6.2.5",
"babel-preset-es2015": "6.16.0",
"css-loader": "0.25.0",
"file-loader": "0.9.0",
"html-loader": "0.4.4",
"html-webpack-plugin": "2.24.0",
"material-ui": "^0.19.4",
"open-browser-webpack-plugin": "0.0.2",
"rimraf": "2.5.4",
"style-loader": "0.13.1",
"webpack": "^3.7.1",
"webpack-dashboard": "0.2.0",
"webpack-dev-server": "1.16.2"
}
}
执行此操作后,我现在在运行npm start后遇到以下控制台错误:
Uncaught Error: Cannot find module "."
at webpackMissingModule (source-map-generator.js:8)
at Object.<anonymous> (source-map-generator.js:8)
at Object../node_modules/source-map/lib/source-map/source-map-generator.js (source-map-generator.js:399)
at __webpack_require__ (bootstrap bf59d56b93d65ff61848:669)
at fn (bootstrap bf59d56b93d65ff61848:87)
at Object../node_modules/source-map/lib/source-map.js (source-map.js:6)
at __webpack_require__ (bootstrap bf59d56b93d65ff61848:669)
at fn (bootstrap bf59d56b93d65ff61848:87)
at Object../node_modules/react-error-overlay/lib/utils/getSourceMap.js (getSourceMap.js:1)
at __webpack_require__ (bootstrap bf59d56b93d65ff61848:669)
以下是我当前的环境设置:
- npm版本5.5.1
- 节点版本7.3.0
- 视窗10
有人知道可能是什么问题吗?环顾四周,react脚本(1.0.14)的最新版本似乎有一个修复程序,但我正在npm安装后运行该程序。我不知道,但您的代码中似乎有错误,您试图从错误的包导入交换机和路由。React-router-3版本和React-router dom-4版本,所以您的代码应该如下所示
import { Switch, Route } from 'react-router-dom';
您的npm版本比较旧,能否更新到最新版本并重试<代码>npm i-gnpm@latest打得好。我进行了更新和编辑。我的npm版本现在是5.5.1。不幸的是,这个问题仍然存在。我还重新安装了node_modules文件夹和npm,但没有成功:(好的。既然你已经更新了并且问题仍然存在,我们需要查看你的webpack.config.js文件,也许还有app.js文件。我的解决方案中目前没有webpack.config.js,有必要吗?
const path = require('path');
const webpack = require('webpack');
const htmlPlugin = require('html-webpack-plugin');
const openBrowserPlugin = require('open-browser-webpack-plugin');
const dashboardPlugin = require('webpack-dashboard/plugin');
const autoprefixer = require('autoprefixer');
const PATHS = {
app: path.join(__dirname, 'src'),
images:path.join(__dirname,'src/assets/'),
build: path.join(__dirname, 'dist')
};
const options = {
host:'localhost',
port:'1234'
};
module.exports = {
entry: {
app: path.join(PATHS.app,'index.js')
},
output: {
path: PATHS.build,
filename: 'bundle.[hash].js'
},
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
stats: 'errors-only',
host: options.host,
port: options.port
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
cacheDirectory: true,
presets: ['es2015']
}
},
{ test: /\.css$/, loader: 'style-loader!css-loader' },
{
test: /\.(ico|jpg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
loader: 'file',
query: {
name: '[path][name].[ext]'
}
},
]
},
plugins:[
new dashboardPlugin(),
new webpack.HotModuleReplacementPlugin({
multiStep: true
}),
new htmlPlugin({
template:path.join(PATHS.app,'index.html'),
inject:'body'
}),
new openBrowserPlugin({
url: `http://${options.host}:${options.port}`
})
]
};
import { Switch, Route } from 'react-router-dom';