【问题标题】:package.json bug with npm init -y installnpm init -y install 的 package.json 错误
【发布时间】:2020-09-27 09:14:22
【问题描述】:

为了 sass 编译,我安装了 node.js,我现在还没有接触过任何 javascript,所以我为解决这个问题而经历的所有文档对我来说真的很复杂。因此,当我将 npm init -y 命令放入 VScode 终端时,它会安装 package.json 文件,该文件在第 5 行和第 6 行之间具有调试属性。

当我点击终端时显示的“调试”错误是这些......

"Error: no test specified" 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! c@1.0.0 test: `echo "Error: no test specified" && exit 1`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the c@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\AppData\Roaming\npm-cache\_logs\2020-09-27T00_42_32_091Z-debug.log
Waiting for the debugger to disconnect...
PS C:\Users\Desktop\c> 

这里是日志文件

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'test'
1 verbose cli ]
2 info using npm@6.14.8
3 info using node@v14.11.0
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle c@1.0.0~pretest: c@1.0.0
6 info lifecycle c@1.0.0~test: c@1.0.0
7 verbose lifecycle c@1.0.0~test: unsafe-perm in lifecycle true
8 verbose lifecycle c@1.0.0~test: PATH: C:\Users\\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\\Desktop\c\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\\AppData\Local\Microsoft\WindowsApps;C:\Users\\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\\AppData\Roaming\npm
9 verbose lifecycle c@1.0.0~test: CWD: C:\Users\\Desktop\c
10 silly lifecycle c@1.0.0~test: Args: [ '/d /s /c', 'echo "Error: no test specified" && exit 1' ]
11 silly lifecycle c@1.0.0~test: Returned: code: 1  signal: null
12 info lifecycle c@1.0.0~test: Failed to exec test script
13 verbose stack Error: c@1.0.0 test: `echo "Error: no test specified" && exit 1`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:314:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:314:20)
13 verbose stack     at maybeClose (internal/child_process.js:1047:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid c@1.0.0
15 verbose cwd C:\Users\\Desktop\c
16 verbose Windows_NT 10.0.19041
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
18 verbose node v14.11.0
19 verbose npm  v6.14.8
20 error code ELIFECYCLE
21 error errno 1
22 error c@1.0.0 test: `echo "Error: no test specified" && exit 1`
22 error Exit status 1
23 error Failed at the c@1.0.0 test script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

【问题讨论】:

    标签: node.js npm sass


    【解决方案1】:

    VScode 为您提供了一种运行“npm test”的快速方法,该方法完全按预期运行。您可以在“脚本”属性中指定要运行的命令。如您所见,有一个用于“测试”,它准确地输出那里写的内容。这就是“调试”的作用。您需要在那里挂钩一个真正的测试命令,以便调试执行任何有用的操作。

    【讨论】:

      【解决方案2】:

      调试内容是 npm run test 的输出,如果您只安装 package.json 以便您可以安装 sass 进行开发,则无需关心它。如果您希望能够通过 npm run test 运行测试,请更改第 7 行的键/值对的值以运行您的测试。

        "test": "someTestCommand.exe"
      

      但同样,如果您只是为了获得 sass 编译而这样做,您可以放心地忽略它。

      【讨论】:

        猜你喜欢
        • 2019-12-17
        • 2017-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-19
        相关资源
        最近更新 更多