尝试导入错误:“SomeObject"未从文件中导出

尝试导入错误:“SomeObject

问题描述:

我已经从 3 升级到了 Webpack 4.从那以后,我收到了很多关于未从某些文件导出的导入的警告.

I've upgraded to Webpack 4 from 3. Since then, I get a lot of warnings regarding imports that were not exported from certain files.

./packages/utils/logging/index.ts
Attempted import error: ‘Options' is not exported from './loggers/log'.
 @ ./packages/utils/index.ts
 @ ./src/App.tsx
 @ multi whatwg-fetch @babel/polyfill ./src/App.tsx

我使用 ts-loaderForkTsCheckerWebpackPlugin.我检查了警告的导出,它们看起来不错.该代码确实有效,但我仍然收到这些警告.

I use ts-loader along with ForkTsCheckerWebpackPlugin. I've examined the exports from the warnings and they look good. The code does work, however I still get those warnings.

tsconfig.json 供参考:

{
  "compilerOptions": {
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "baseUrl": ".",
    "sourceMap": true,
    "allowJs": true,
    "jsx": "react",
    "moduleResolution": "node",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "allowSyntheticDefaultImports": true,
    "skipLibCheck": true,
    "resolveJsonModule": true
  },
  "include": ["packages/**/*"],
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "webpack",
    "**/__tests__/*"
  ]
}

Webpack 配置:

Webpack config:

...
module: {
    rules: [
      {
        test: /\.(ts|tsx|d.ts)$/,
        exclude: /node_modules/,
        use: {
          loader: 'ts-loader',
          options: {
            transpileOnly: true,
          },
        },
      },
      {
        test: /\.(js|jsx|mjs)$/,
        include: [paths.packagesSrc, ...paths.modulesToTranspile],
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader?cacheDirectory=true',
          options: {
            configFile: paths.configFiles.babel,
          },
        },
      },
      ...
    ]
},
plugins: [
    ...
    new ForkTsCheckerWebpackPlugin({
      async: options.asyncTypeChecking,
      checkSyntacticErrors: true,
      tsconfig: paths.appTsConfig,
      watch: paths.packagesSrc,
    }),
    ...
],
...

在 Typescript 中重新导出类型时,Webpack 4 中的 ts-loader 似乎存在问题.
可以忽略警告.

Seems like there is a problem with ts-loader in Webpack 4 when re-exporting types in Typescript.
The warnings can be ignored.

参考