0

我正在导入一个包含 Typescript 和 JS 文件的节点模块文件夹。我将 ts-loader 用于打字稿,但由于某种原因,它会创建一长串错误,我认为这是因为两个文件都在一起。我自己无法触摸这些文件,所以也许有更好的方法来配置 ts-loader?

这是我的 tsconfig.json

{
"compilerOptions": {
    "target": "es2015",
    "module": "es2015",
    "moduleResolution": "node",
    "declaration": false,
    "outDir": "lib",
    "strict": false,
    "allowJs": true,
    "jsx": "react",
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noResolve": false
},
"include": [
    "./standalone/**/*",
    "./node_modules/**/*"
],
}

一些错误是:

ERROR in ./node_modules/project/frontend/react/shared/inputs/smallcolorinput.tsx Module build failed (from ./node_modules/ts-loader/index.js): Error: Typescript emitted no output for ../FrontEnd/ProjectFolder/node_modules/project/frontend/react/shared/inputs/smallcolorinput.tsx. at successLoader (../FrontEnd/ProjectFolder/node_modules/ts-loader/dist/index.js:41:15) at Object.loader (../FrontEnd/ProjectFolder/node_modules/ts-loader/dist/index.js:21:12) @ ./node_modules/project/frontend/react/shared/views/FontSettings.jsx 13:23-59 @ ./node_modules/project/frontend/react/shared/views/ThemeEditor.jsx @ ./node_modules/project/frontend/react/editor/editor.jsx @ ./electron/views/Edit.tsx

这是网络包配置:

return {
        devtool: devMode ? 'eval' : 'hidden-source-map',
        module: {
            rules: [
                {
                    test: /\.(ts|tsx)?$/,
                    use: [babelLoader, {
                        loader: 'ts-loader',
                        options: {
                            onlyCompileBundledFiles: true,
                            allowTsInNodeModules: true
                        }
                    }],
                    exclude: /node_modules\/(?!(project)\/).*/

                },
                {
                    test: /\.(css|scss)?$/,
                    use:  ['style-loader', MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
                },
                {
                    test: /.jsx?$/,
                    use: babelLoader,
                    exclude: /node_modules\/(?!(project)\/).*/
                },
},resolve: {
            symlinks: false,
            modules: [
                path.resolve(basePath, "node_modules"),

            ],
            extensions: ['.js', '.jsx', '.ts', '.tsx'],
            alias: {

                'classnames': path.join(basePath, 'node_modules/project/lib/utils/classnames.js')
            }
        },
4

1 回答 1

3

经过大量寻找和尝试不同的答案后,我发现 Typescript 在从 node_modules 编译 ts 文件时存在问题。之前不支持,现在 ts-loader 正式支持了。

我发现删除onlyCompileBundledFilests-loader 可以解决这些问题。

于 2018-08-27T07:29:20.537 回答