【发布时间】:2019-09-04 22:59:47
【问题描述】:
我无法运行从 github 克隆的 react 项目。
克隆后,本地运行项目的步骤为:
- 从 package.json 安装依赖项:
npm install && cd doc && npm install - 要在本地服务器上运行文档页面:
npm run docs:dev
我已经尝试将 package.json 中的行添加为 - "start": "webpack-dev-server --config=config/webpack.dev.js" 在 "scripts" 中显示错误。 文件package.json之前没有“start”,后来我加了。
这是我的 package.json 文件,只有“脚本”部分:
"scripts": {
"start": "webpack-dev-server --config=config/webpack.dev.js",
"docs:dev": "cd doc && npm run develop",
"prebuild": "rm -rf dist components && npm run lint:fix",
"build": "cross-env NODE_ENV=production webpack -p --config webpack.prod.js",
"lint": "eslint ./ --ext .jsx --ext .js && echo \"eslint: no lint errors!\"",
"lint:fix": "eslint ./ --ext .jsx --ext .js --fix && echo \"eslint: all errors fixed!\"",
"test": "nyc mocha --require @babel/register --require jsdom-global/register --require test/testSetup.js --require test/ignoreStyles.js 'lib/**/*.test.js'",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"semantic-release": "semantic-release"
},
在“脚本”中添加行时出现的错误 “开始”:“webpack-dev-server --config=config/webpack.dev.js”是:
module.js:549
throw err;
^
Error: Cannot find module 'C:\Users\Pranav\Documents\GitHub\react-lite-ui\config
\webpack.dev.js'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at WEBPACK_OPTIONS (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_modu
les\webpack-cli\bin\convert-argv.js:133:13)
at requireConfig (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_module
s\webpack-cli\bin\convert-argv.js:135:6)
at C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_modules\webpack-cli\b
in\convert-argv.js:142:17
at Array.forEach (<anonymous>)
at module.exports (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_modul
es\webpack-cli\bin\convert-argv.js:140:15)
at Object.<anonymous> (C:\Users\Pranav\Documents\GitHub\react-lite-ui\node_m
odules\webpack-dev-server\bin\webpack-dev-server.js:92:55)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-lite-ui@1.0.2 start: `webpack-dev-server --config=config/webpack.
dev.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the react-lite-ui@1.0.2 start script.
npm ERR! This is probably not a problem with npm. There is likely additional log
ging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Pranav\AppData\Roaming\npm-cache\_logs\2019-04-15T07_57_27
_526Z-debug.log
这是 webpack.config.js 文件
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
devtool: 'inline-source-map',
mode: 'development',
});
我希望项目应该使用 npm run start 运行,但我收到了这个错误。
【问题讨论】:
-
你得到的错误和堆栈跟踪是什么?
-
你能发布 config/webpack.dev.js 吗?
-
感谢您的回复...我已经编辑了上面的帖子,其中包含错误
-
你发布了 webpack.config.js。您应该查找 webpack.dev.js,因为这是脚本中引用的内容
-
对不起,错误地发布了 webpack.config.js... 我没有 webpack.dev.js 文件
标签: reactjs package.json