代码之家  ›  专栏  ›  技术社区  ›  Karlom

安装react路由器dom后,react不会启动

  •  0
  • Karlom  · 技术社区  · 6 年前

    我是新来的反应,问题是:

    在我安装的Ubuntu机器上,我的react应用程序运行得很好 react-router-dom

    npm i --save  react-router-dom
    

    现在我再也不能做出反应了:

    me@desktop:~/front-myapp$ npm start
    
    > front-myapp@0.1.0 start /home/me/front-myapp
    > react-scripts start
    
    sh: 1: react-scripts: not found
    npm ERR! file sh
    npm ERR! code ELIFECYCLE
    npm ERR! errno ENOENT
    npm ERR! syscall spawn
    npm ERR! front-myapp@0.1.0 start: `react-scripts start`
    npm ERR! spawn ENOENT
    npm ERR! 
    npm ERR! Failed at the front-myapp@0.1.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!     /home/me/.npm/_logs/2018-09-03T04_38_54_369Z-debug.log
    

    错误日志文件如下:

    0 info it worked if it ends with ok
    1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
    2 info using npm@5.6.0
    3 info using node@v8.11.4
    4 verbose run-script [ 'prestart', 'start', 'poststart' ]
    5 info lifecycle front-myapp@0.1.0~prestart: front-myapp@0.1.0
    6 info lifecycle front-myapp@0.1.0~start: front-myapp@0.1.0
    7 verbose lifecycle front-myapp@0.1.0~start: unsafe-perm in lifecycle true
    8 verbose lifecycle front-myapp@0.1.0~start: PATH: /usr/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/me$
    9 verbose lifecycle front-myapp@0.1.0~start: CWD: /home/me/front-myapp
    10 silly lifecycle front-myapp@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
    11 info lifecycle front-myapp@0.1.0~start: Failed to exec start script
    12 verbose stack Error: front-myapp@0.1.0 start: `react-scripts start`
    12 verbose stack spawn ENOENT
    12 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18)
    12 verbose stack     at emitTwo (events.js:126:13)
    12 verbose stack     at ChildProcess.emit (events.js:214:7)
    12 verbose stack     at maybeClose (internal/child_process.js:925:16)
    12 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
    13 verbose pkgid front-myapp@0.1.0
    14 verbose cwd /home/me/front-myapp
    15 verbose Linux 4.15.0-33-generic
    16 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
    17 verbose node v8.11.4
    18 verbose npm  v5.6.0
    19 error file sh
    20 error code ELIFECYCLE
    21 error errno ENOENT
    22 error syscall spawn
    23 error front-myapp@0.1.0 start: `react-scripts start`
    23 error spawn ENOENT
    24 error Failed at the front-myapp@0.1.0 start script.
    24 error This is probably not a problem with npm. There is likely additional logging output above.
    25 verbose exit [ 1, true ]
    

    我的包.json:

    {
      "name": "front-myapp",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "react": "^16.4.2",
        "react-dom": "^16.4.2",
        "react-router": "^4.3.1",
        "react-router-dom": "^4.3.1",
        "react-scripts": "1.1.5"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    }
    

    我怎样才能解决这个问题?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Alex Antonov    6 年前

    1. rm -rf node_modules
    2. npm install

    应该会成功的。

    react-scripts 是一个有点麻烦的包,所以很可能,它已经从 node_modules