Attempted import error: 'SomeObject' is not exported from file

这一生的挚爱 提交于 2019-12-11 02:54:34

问题


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

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 for reference:

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

回答1:


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

Reference



来源:https://stackoverflow.com/questions/54553728/attempted-import-error-someobject-is-not-exported-from-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!