NodeJS 切换到开发分支时出现意外标记

ogq8wdun  于 2022-12-12  发布在  Node.js
关注(0)|答案(1)|浏览(140)

我用下面的命令安装了一个新的网站。但是当我试图创建一个开发分支时,我得到了一些奇怪的错误。

gatsby new static-website https://github.com/gatsbyjs/gatsby-starter-default

当我尝试切换到开发分支时,我得到以下错误。

root@app01:~/static-website# gatsby develop
gatsby develop

Start development server. Watches files, rebuilds, and hot reloads if something changes

Options:
  --verbose                   Turn on verbose output                                                                                                   [boolean] [default: false]
  --no-color, --no-colors     Turn off the color in output                                                                                             [boolean] [default: false]
  -H, --host                  Set host. Defaults to localhost                                                                                     [string] [default: "localhost"]
  -p, --port                  Set port. Defaults to 8000                                                                                               [string] [default: "8000"]
  -o, --open                  Open the site in your (default) browser for you.                                                                                          [boolean]
  -S, --https                 Use HTTPS. See https://www.gatsbyjs.org/docs/local-https/ as a guide                                                                      [boolean]
  -c, --cert-file             Custom HTTPS cert file (relative path; also required: --https, --key-file). See https://www.gatsbyjs.org/docs/local-https/   [string] [default: ""]
  -k, --key-file              Custom HTTPS key file (relative path; also required: --https, --cert-file). See https://www.gatsbyjs.org/docs/local-https/   [string] [default: ""]
  --open-tracing-config-file  Tracer configuration file (OpenTracing compatible). See https://gatsby.dev/tracing                                                         [string]
  -h, --help                  Show help                                                                                                                                 [boolean]
  -v, --version               Show version number                                                                                                                       [boolean]
error There was a problem loading the local develop command. Gatsby may not be installed. Perhaps you need to run "npm install"?

  Error: /root/static-website/node_modules/gatsby-cli/lib/reporter/loggers/ink/index.js:13111
    const lineNumber = location?.start.line;
                                ^
  SyntaxError: Unexpected token '.'

  - loader.js:915 wrapSafe
    internal/modules/cjs/loader.js:915:16

  - loader.js:963 Module._compile
    internal/modules/cjs/loader.js:963:27

  - loader.js:1027 Object.Module._extensions..js
    internal/modules/cjs/loader.js:1027:10

  - loader.js:863 Module.load
    internal/modules/cjs/loader.js:863:32

  - loader.js:708 Function.Module._load
    internal/modules/cjs/loader.js:708:14

  - loader.js:887 Module.require
    internal/modules/cjs/loader.js:887:19

  - helpers.js:74 require
    internal/modules/cjs/helpers.js:74:18

  - start-logger.js:41 startLogger
    [static-website]/[gatsby-cli]/lib/reporter/start-logger.js:41:5

  - index.js:15 Object.<anonymous>
    [static-website]/[gatsby-cli]/lib/reporter/index.js:15:30

  - loader.js:999 Module._compile
    internal/modules/cjs/loader.js:999:30

我测试了gatsby@2.5.0和最新版本,同样的错误。

root@app01:~/static-website# npm list -g --depth=0
/usr/local/lib
└── gatsby-cli@2.5.0

root@app01:~/static-website# npm list -g --depth=0
/usr/local/lib
└── gatsby-cli@5.2.0
mspsb9vt

mspsb9vt1#

想通了。
当我们使用apt-get在ubuntu 22.04上安装nodejs时,它会安装旧版本(node v12.22.9)。
我按照这个documentation安装了最新版本的nodejs(v18.12.1)和npm(8.19.2)。
现在,如果我运行gatsby develop,则不会出现错误。

相关问题