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

时间:2019-02-06 12:30:49

标签: reactjs typescript webpack webpack-4 ts-loader

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

./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一起使用。 我已经检查了警告中的出口,它们看起来不错。该代码确实有效,但是我仍然收到那些警告。

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配置:

...
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,
    }),
    ...
],
...

1 个答案:

答案 0 :(得分:2)

当重新导出Typescript中的类型时,Webpack 4中的User似乎有问题。
警告可以忽略。

Reference