[eggjs/egg]脚手架搭建时出现问题

2025-11-04 497 views
0
What happens?

按照文档脚手架搭建项目时, 第一步npm init egg --type=simple是成功的 第二步npm i

npm WARN deprecated @types/urllib@2.33.0: This is a stub types definition. urllib provides its own type definitions, so you do not need this installed.
npm WARN deprecated circular-json@0.5.9: CircularJSON is in maintenance only, flatted is its successor.
npm ERR! Unexpected end of JSON input while parsing near '...1.0","debug":"^3.0.1"'

npm ERR! A complete log of this run can be found in:
/Users/lyk/.npm/_logs/2019-05-29T05_56_57_780Z-debug.log
Context Node Version:10.15.3

回答

8

提交生成的仓库

5

https://github.com/onepiecelyk/egg-demo

4
➜  tmp gcl git@github.com:onepiecelyk/egg-demo.git
Cloning into 'egg-demo'...
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 19 (delta 0), reused 19 (delta 0), pack-reused 0
Receiving objects: 100% (19/19), done.
➜  tmp cd egg-demo
➜  egg-demo git:(master) npm i --no-package-lock
npm WARN deprecated @types/urllib@2.33.0: This is a stub types definition. urllib provides its own type definitions, so you do not need this installed.
npm WARN deprecated circular-json@0.5.9: CircularJSON is in maintenance only, flatted is its successor.

> fsevents@1.2.9 install /Users/tz/Workspaces/tmp/egg-demo/node_modules/fsevents
> node install

node-pre-gyp WARN Using needle for node-pre-gyp https download
[fsevents] Success: "/Users/tz/Workspaces/tmp/egg-demo/node_modules/fsevents/lib/binding/Release/node-v64-darwin-x64/fse.node" is installed via remote

> core-js@2.6.9 postinstall /Users/tz/Workspaces/tmp/egg-demo/node_modules/core-js
> node scripts/postinstall || echo "ignore"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

> egg-ci@1.12.0 postinstall /Users/tz/Workspaces/tmp/egg-demo/node_modules/egg-ci
> node install.js

[egg-ci] create /Users/tz/Workspaces/tmp/egg-demo/.travis.yml success
[egg-ci] create /Users/tz/Workspaces/tmp/egg-demo/appveyor.yml success
npm WARN co-mocha@1.2.2 requires a peer of mocha@>=1.18 <6 but none is installed. You must install peer dependencies yourself.
npm WARN acorn-jsx@5.0.1 requires a peer of acorn@^6.0.0 but none is installed. You must install peer dependencies yourself.

added 1249 packages from 1065 contributors and audited 18255 packages in 33.579s
found 1 high severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

无法复现,看你的报错日志,是某个包的 package.json 出问题了,不合法。

这个属于 npm 安装依赖的问题了,跟 egg 关系不大,需要你自己排查下。 (PS:你们是不是用了自己的 registry 源)

9

没有用自己的registry源,直接使用npm源

6

npm ERR! Unexpected end of JSON input while parsing near '...1.0","debug":"^3.0.1"'

可以自己搜下本地 node_modules 有哪个 JSON 是类似这样的,看看具体啥原因。

无法复现的我们没法排查,这个大概率是 npm 安装依赖的问题,环境相关,还没到 egg 那层。

6

为什么我用 npm init egg --type=simple 只是创建了个 package.json 文件(相当于执行npm init), 用 egg-init --type=simple 才能正常创建项目?

1

@yishaoZhang 可能是你的 npm 版本太低了, npm init <initializer> 这个好像是 5.8 之后支持的。 https://docs.npmjs.com/cli/init