在 Angular 2 中需要模块时找不到模块“.package.json”?

Cannot find module ".package.json" when requiring a module in Angular 2?

我正在尝试将节点模块导入到我的 Angular 2 应用程序中:

const node-module = require('some-module');

在控制台中,我总是收到错误

ERROR in ./~/some-module/package.json
Module parse failed: /home/tom/Projects/project/node_modules/some-module     /package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)

我正在使用 Webpack 来捆绑模块,但我真的不明白为什么会失败。 在 Angular 2 个应用程序中是否有其他导入节点模块的方法?

我认为它甚至试图加载 package.json 它不应该。如果可行,您可以尝试 json-loader,但它不应编译 package.json,package.json 应排除在捆绑之外。