Я пытаюсь настроить next.js с помощью express и node.js. В терминале произошла ошибка при попытке запустить локальный сервер с экспрессом и узлом. Я получаю следующую ошибку, когда 'npm run dev' используется в командной строке.
Package.json:
{
"name": "nextjs",
"description": "NextJS Tutorial",
"version": "1.0.0",
"scripts": {
"dev": "node server/index.js"
},
"dependencies": {
"@zeit/next-sass": "^1.0.1",
"babel-plugin-module-resolver": "^3.1.1",
"babel-plugin-wrap-in-js": "^1.1.1",
"express": "^4.16.4",
"next": "^7.0.2",
"node-sass": "^4.11.0",
"postcss-easy-import": "^3.0.0",
"postcss-loader": "^3.0.0",
"raw-loader": "^1.0.0",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"sass-loader": "^7.1.0",
"tailwindcss": "^0.7.3"
},
"devDependencies": {
"autoprefixer": "^9.4.5"
}
}
Мой сервер / index.js выглядит следующим образом:
const express = require('express');
const next = require('next');
const PORT = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app
.prepare().then(() => {
const server = express();
app.use(bodyParser.json());
server.get('*', (req,res) => {
return handle(req,res);
});
server.listen(PORT, () => {
if (err) throw err;
console.log('> Ready on ${PORT}');
});
})
Журнал ошибок выглядит следующим образом:
0 info it worked if it ends with ok
1 verbose cli [ '/Users/hvnwntw8/.nvm/versions/node/v10.14.1/bin/node',
1 verbose cli '/Users/hvnwntw8/.nvm/versions/node/v10.14.1/bin/npm',
1 verbose cli 'run',
1 verbose cli 'dev' ]
2 info using npm@6.5.0
3 info using node@v10.14.1
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle nextjs@1.0.0~predev: nextjs@1.0.0
6 info lifecycle nextjs@1.0.0~dev: nextjs@1.0.0
7 verbose lifecycle nextjs@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle nextjs@1.0.0~dev: PATH: /Users/hvnwntw8/.nvm/versions/node/v10.14.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/hvnwntw8/Projects/nextjs/node_modules/.bin:/Users/hvnwntw8/.rbenv/shims:/Users/hvnwntw8/.global-modules/bin:/Users/hvnwntw8/.nvm/versions/node/v10.14.1/bin:/Users/hvnwntw8/anaconda3/bin:/usr/local/opt/python/libexec/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mongodb/bin:/opt/yarn-[1.12.3]/bin
9 verbose lifecycle nextjs@1.0.0~dev: CWD: /Users/hvnwntw8/Projects/nextjs
10 silly lifecycle nextjs@1.0.0~dev: Args: [ '-c', 'node sever/index.js' ]
11 silly lifecycle nextjs@1.0.0~dev: Returned: code: 1 signal: null
12 info lifecycle nextjs@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: nextjs@1.0.0 dev: `node sever/index.js`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/Users/hvnwntw8/.nvm/versions/node/v10.14.1/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:182:13)
13 verbose stack at ChildProcess.<anonymous> (/Users/hvnwntw8/.nvm/versions/node/v10.14.1/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:182:13)
13 verbose stack at maybeClose (internal/child_process.js:962:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid nextjs@1.0.0
15 verbose cwd /Users/hvnwntw8/Projects/nextjs
16 verbose Darwin 18.2.0
17 verbose argv "/Users/hvnwntw8/.nvm/versions/node/v10.14.1/bin/node" "/Users/hvnwntw8/.nvm/versions/node/v10.14.1/bin/npm" "run" "dev"
18 verbose node v10.14.1
19 verbose npm v6.5.0
20 error code ELIFECYCLE
21 error errno 1
22 error nextjs@1.0.0 dev: `node sever/index.js`
22 error Exit status 1
23 error Failed at the nextjs@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
Я попробовал 'npm clean cache -f', затем 'npm verify', удалив мой package-lock.json и папку узловых модулей и запустив 'npm install' в терминале. Все еще не повезло. Буду признателен за любую оказанную помощь.