我通过express-generator
安装模板,我启动了它,没关系。之后,我将添加到项目包admin-bro
和admin-bro-expressjs
中。安装后,我尝试使用npm start
命令,但出现错误。我不明白为什么它不运行,包React存在于node_modules
中。您可以在下面看到的代码package.json
。
{
"name": "my_project",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"admin-bro": "^0.8.8",
"admin-bro-expressjs": "^0.1.7",
"admin-bro-mongoose": "^0.2.2",
"cookie-parser": "~1.4.4",
"debug": "~4.1.1",
"express": "~4.17.1",
"express-session": "^1.16.2",
"hbs": "~4.0.4",
"http-errors": "~1.7.2",
"morgan": "~1.9.1"
}
}
控制台中的错误:
PS D:\my_project> npm start
> my_project@0.0.0 start D:\my_project
> node ./bin/www
D:\my_project\node_modules\admin-bro\src\frontend\login-template.js:1
import React from 'react'
^^^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:721:23)
at Module._compile (D:\my_project\node_modules\pirates\lib\index.js:99:24)
at Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Object.newLoader [as .js] (D:\my_project\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (D:\my_project\node_modules\admin-bro\src\admin-bro.js:5:23)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my_project@0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my_project@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\vsevo\AppData\Roaming\npm-cache\_logs\2019-06-19T23_28_03_159Z-debug.log
答案 0 :(得分:0)
如果要启动Express,则应这样导入
const react = require('React');
如果它在React上,请改为这样做
import React, { Component } from 'react';
修改
需要R,而不是r
顺便说一句,您忘记了NPM安装反应