#reactjs #express #webpack #server-side-rendering #package.json
#reactjs #экспресс #webpack #рендеринг на стороне сервера #package.json
Вопрос:
я немного новичок во всей этой концепции, так что извините, если мой вопрос звучит глупо или не по теме,
это мой webpack
конфиг
const path = require('path');
module.exports = {
// inform webpack that we're building a bundle
// for nodeJS, rather than for the browser
target: 'node',
// Tell webpack the root file of our server application
entry: "./src/index.js",
// Tell webpack where to put the output file that is generated
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build')
},
// Tell webpack to run babel on every file it runs through
module: {
rules: [
{
test: /.js?$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: [
'react',
'stage-0',
['env', {
targets: {
browsers: ['last 2 versions']
}
}]
]
}
}
]
}
};
и это мой package.json
:
{
"name": "react-ssr",
"version": "1.0.0",
"description": "Server side rendering project",
"main": "index.js",
"scripts": {
"dev:server": "nodemon --watch build --exec "node build/bundle.js"",
"dev:build:server": "webpack --confing webpack.server.js --watch"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "0.16.2",
"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-preset-env": "1.6.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-es2017": "6.24.1",
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "6.24.1",
"compression": "1.7.0",
"concurrently": "3.5.0",
"express": "4.15.4",
"express-http-proxy": "1.0.6",
"lodash": "4.17.4",
"nodemon": "1.12.0",
"npm-run-all": "4.1.1",
"react": "16.0.0",
"react-dom": "16.0.0",
"react-helmet": "5.2.0",
"react-redux": "5.0.6",
"react-router-config": "1.0.0-beta.4",
"react-router-dom": "4.2.2",
"redux": "3.7.2",
"redux-thunk": "2.2.0",
"serialize-javascript": "1.4.0",
"webpack": "3.5.6",
"webpack-dev-server": "2.8.2",
"webpack-merge": "4.1.0",
"webpack-node-externals": "1.6.0"
}
}
но всякий раз, когда я пытаюсь выполнить команду npm run dev:server
, я получаю приведенные ниже ошибки, и, похоже, я не знаю, в чем проблема:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'dev:server'
1 verbose cli ]
2 info using npm@6.13.4
3 info using node@v12.14.1
4 verbose run-script [ 'predev:server', 'dev:server', 'postdev:server' ]
5 info lifecycle react-ssr@1.0.0~predev:server: react-ssr@1.0.0
6 info lifecycle react-ssr@1.0.0~dev:server: react-ssr@1.0.0
7 verbose lifecycle react-ssr@1.0.0~dev:server: unsafe-perm in lifecycle true
8 verbose lifecycle react-ssr@1.0.0~dev:server: PATH: C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclenode-gyp-bin;C:UsersAliDesktopServernode_modules.bin;C:UsersAliAppDataRoamingnpm;C:Program Filesnodejs
9 verbose lifecycle react-ssr@1.0.0~dev:server: CWD: C:UsersAliDesktopServer
10 silly lifecycle react-ssr@1.0.0~dev:server: Args: [ '/d /s /c', 'nodemon --watch build --exec "node build/bundle.js"' ]
11 silly lifecycle react-ssr@1.0.0~dev:server: Returned: code: 1 signal: null
12 info lifecycle react-ssr@1.0.0~dev:server: Failed to exec dev:server script
13 verbose stack Error: react-ssr@1.0.0 dev:server: `nodemon --watch build --exec "node build/bundle.js"`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecycleindex.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:223:5)
13 verbose stack at ChildProcess.<anonymous> (C:Program Filesnodejsnode_modulesnpmnode_modulesnpm-lifecyclelibspawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:223:5)
13 verbose stack at maybeClose (internal/child_process.js:1021:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid react-ssr@1.0.0
15 verbose cwd C:UsersAliDesktopServer
16 verbose Windows_NT 6.1.7601
17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev:server"
18 verbose node v12.14.1
19 verbose npm v6.13.4
20 error code ELIFECYCLE
21 error errno 1
22 error react-ssr@1.0.0 dev:server: `nodemon --watch build --exec "node build/bundle.js"`
22 error Exit status 1
23 error Failed at the react-ssr@1.0.0 dev:server script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]