在尝试NPM发布

时间:2017-11-09 13:32:25

标签: javascript node.js npm

我有一个项目我试图作为npm模块发布。它在我的计算机上运行正常,当我在不同的文件夹中导入它时,我可以毫无问题地使用它,但是npm发布给了我这个:

npm ERR! Class constructor  cannot be invoked without 'new'

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/forrest/.npm/_logs/2017-11-09T13_21_57_362Z-debug.log

老实说,我甚至不知道在哪里寻找这种错误 - 我很确定我的代码没有遗漏任何'新'关键字,因为它在我尝试发布之前正确运行。如果这是一个特定于npm的问题,我无法搜索任何内容。

如何修复此错误并成功发布?如果失败了,它会出现什么样的问题以及我的代码应该在哪里?

这是日志文件:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'publish' ]
2 info using npm@5.5.1
3 info using node@v8.6.0
4 verbose npm-session 5adaf2e8823e5058
5 verbose publish [ '.' ]
6 info lifecycle Meristem@1.0.0~prepublish: Meristem@1.0.0
7 info lifecycle Meristem@1.0.0~prepare: Meristem@1.0.0
8 info lifecycle Meristem@1.0.0~prepublishOnly: Meristem@1.0.0
9 info lifecycle Meristem@1.0.0~prepack: Meristem@1.0.0
10 verbose tar pack [ '/var/folders/29/p2_sljq17376p_ycszkbx9rr0000gn/T/npm-35498-ea084a31/tmp/packing-340ae87b/package.tgz',
10 verbose tar pack   '.' ]
11 verbose tarball /var/folders/29/p2_sljq17376p_ycszkbx9rr0000gn/T/npm-35498-ea084a31/tmp/packing-340ae87b/package.tgz
12 verbose folder .
13 verbose stack TypeError: Class constructor  cannot be invoked without 'new'
13 verbose stack     at pack_ (/usr/local/lib/node_modules/npm/lib/utils/tar.js:213:15)
13 verbose stack     at /usr/local/lib/node_modules/npm/lib/utils/tar.js:45:7
13 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:115:5
13 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:402:5
13 verbose stack     at checkBinReferences_ (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:357:45)
13 verbose stack     at final (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:400:3)
13 verbose stack     at then (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:160:5)
13 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:348:12
13 verbose stack     at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
13 verbose stack     at tryToString (fs.js:514:3)
13 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:502:12)
14 verbose cwd /Users/forrest/web-projects/meristem
15 verbose Darwin 14.5.0
16 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "publish"
17 verbose node v8.6.0
18 verbose npm  v5.5.1
19 error Class constructor  cannot be invoked without 'new'
20 verbose exit [ 1, true ]

here's the code I'm trying to publish

1 个答案:

答案 0 :(得分:0)

  

它是什么类型的问题,我的代码应该在哪里?

通过尝试npm pack命令(创建包的tar包但不发布它)在一个简单的测试文件夹上,没有有效的package.json,但我的代码都没有,我是能够发现这是NPM本身的问题,而不是我的代码。

  

如何修复此错误并成功发布?

虽然我在尝试发布之前不久更新了NPM,但我再次这样做了(使用npm install npm@latest -g),这似乎解决了这个问题。