【问题标题】:Webpack ts-loader error in node_modules/@typesnode_modules/@types 中的 Webpack ts-loader 错误
【发布时间】:2017-06-11 19:24:44
【问题描述】:

我的项目编译正常,但如果我在新目录中签出并尝试npm install 然后webpack,我会收到以下错误:

ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts
(500,12): error TS1005: ',' expected.

ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts
(502,12): error TS1005: ',' expected.

ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts
(504,15): error TS1005: ',' expected.

ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts
(505,15): error TS1005: ',' expected.

ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts
(506,15): error TS1005: ',' expected.

ERROR in /home/nobody/myproject/server/node_modules/@types/mongodb/index.d.ts
(1002,23): error TS1005: ',' expected.

以及同一文件中的大约 25 个其他错误,以及我的一些源文件中的其他错误。

在我的 tsconfig.json 中,我排除了 node_modules,并且我还设置了 webpack externals 用于打包 node_modules 与 node express 后端:

var nodeModules = {};
fs.readdirSync('node_modules')
    .filter(function (x) {
        return ['.bin'].indexOf(x) === -1;
    })
    .forEach(function (mod) {
        nodeModules[mod] = 'commonjs ' + mod;
    });

我真的不明白为什么在我的开发目录中一切正常,但如果我把它放在另一个目录中,它就会中断。

【问题讨论】:

    标签: typescript webpack ts-loader


    【解决方案1】:

    您使用的是什么版本的 TypeScript? The current version of Mongo's .d.ts 文件使用默认类型参数开始,这些参数在 TypeScript 2.3 中发布。文件中还有 20 多个默认类型参数,这听起来像是您看到的解析错误的数量。

    简而言之,您可能只需要升级到 TypeScript 2.3。

    【讨论】:

    • 我想给你投一百万分,但我不会让我点击不止一次...
    猜你喜欢
    • 2017-06-30
    • 2017-08-23
    • 1970-01-01
    • 2019-07-18
    • 2018-03-07
    • 2017-04-16
    • 2017-05-27
    • 2021-05-05
    • 2020-08-21
    相关资源
    最近更新 更多