javascript - 如何让 npm start 在 Ubuntu 上工作?

标签 javascript node.js reactjs ubuntu npm

我知道这个问题以前曾多次发生在很多人身上,但我昨天花了几个小时试图完成这项工作,但我一生都无法弄清楚。
我正在尝试学习 React,当我尝试使用“npm start”命令时,它是这样的:

$ npm start

> react-app@0.1.0 start /react-app
> /react-app/node_modules/react-scripts/scripts/start.js

    sh: 1: /react-app/node_modules/react-scripts/scripts/start.js: Permission denied
    npm ERR! code ELIFECYCLE
    npm ERR! errno 126
    npm ERR! react-app@0.1.0 start: `/react-app/node_modules/react-scripts/scripts/start.js`
    npm ERR! Exit status 126
    npm ERR! 
    npm ERR! Failed at the react-app@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/sven/.npm/_logs/2020-12-13T06_45_28_430Z-debug.log
我尝试过的事情:
  • 将执行权限添加到“开始”脚本
  • 删除所有 Node 模块,重新安装 Node ,重新创建项目文件
  • 编辑 package.json 以包含启动脚本

  • 在我使用的教程中,这个人只是输入 npm start它没有问题。如果有的话,谁能解释一下npm start在这种情况下呢?我现在真的不知道该怎么办。
    这就是我的 package.json 的样子:
    {
      "name": "react-app",
      "version": "0.1.0",
      "private": true,
      "scripts": {
        "start": "/home/sven/react-app/node_modules/react-scripts/scripts/start.js"
      },
      "dependencies": {
        "react": "^17.0.1",
        "react-dom": "^17.0.1",
        "react-scripts": "4.0.1"
      }
    }
    
    这是日志文件:
    0 info it worked if it ends with ok
    1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
    2 info using npm@6.14.4
    3 info using node@v10.19.0
    4 verbose run-script [ 'prestart', 'start', 'poststart' ]
    5 info lifecycle react-app@0.1.0~prestart: react-app@0.1.0
    6 info lifecycle react-app@0.1.0~start: react-app@0.1.0
    7 verbose lifecycle react-app@0.1.0~start: unsafe-perm in lifecycle true
    8 verbose lifecycle react-app@0.1.0~start: PATH: /usr/share/npm/node_modules/npm-lifecycle/node-gyp-bin:/react-app/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    9 verbose lifecycle react-app@0.1.0~start: CWD: /react-app
    10 silly lifecycle react-app@0.1.0~start: Args: [ '-c',
    10 silly lifecycle   '/react-app/node_modules/react-scripts/scripts/start.js' ]
    11 silly lifecycle react-app@0.1.0~start: Returned: code: 126  signal: null
    12 info lifecycle react-app@0.1.0~start: Failed to exec start script
    13 verbose stack Error: react-app@0.1.0 start: `/react-app/node_modules/react-scripts/scripts/start.js`
    13 verbose stack Exit status 126
    13 verbose stack     at EventEmitter.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/index.js:332:16)
    13 verbose stack     at EventEmitter.emit (events.js:198:13)
    13 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
    13 verbose stack     at ChildProcess.emit (events.js:198:13)
    13 verbose stack     at maybeClose (internal/child_process.js:982:16)
    13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
    14 verbose pkgid react-app@0.1.0
    15 verbose cwd /react-app
    16 verbose Linux 5.4.0-58-generic
    17 verbose argv "/usr/bin/node" "/usr/bin/npm" "start"
    18 verbose node v10.19.0
    19 verbose npm  v6.14.4
    20 error code ELIFECYCLE
    21 error errno 126
    22 error react-app@0.1.0 start: `/react-app/node_modules/react-scripts/scripts/start.js`
    22 error Exit status 126
    23 error Failed at the react-app@0.1.0 start script.
    23 error This is probably not a problem with npm. There is likely additional logging output above.
    24 verbose exit [ 126, true ]
    

    最佳答案

    我也有这个问题。这是因为 REACT PROJECT 根文件夹的权限问题。当“npm start”或“npm run build”时。 react 应用程序将被构建,它需要在 react 项目目录中创建名为“build”的目录。请尝试

    sudo chmod 777 {/path/dir_name}
    
    它对我有用。
    最后确保全局更新“npm”。

    关于javascript - 如何让 npm start 在 Ubuntu 上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65277535/

    相关文章:

    javascript - YUI3 - 具有相同类的链接的 Onclick 事件处理

    javascript - 如何在 React 中正确地将 css 文件包含在我的 index.html 文件中?

    node.js - Rethinkdb 更改提要仅返回更改

    reactjs - dotenv : how to set custom path

    javascript - React js控制componentDidUpdate()方法

    javascript - 如何让菜单默认打开?

    javascript - 仅在需要时使用 jQuery 重新加载数据

    angularjs - 使用 Node.js 和 AngularJS 提供静态文件

    node.js - Node js 中的 LDAP 身份验证支持

    reactjs - React.FC<Props<T>> 中的 GenericType