【问题标题】:Compile error with a lot of errors from webpack编译错误,来自 webpack 的很多错误
【发布时间】:2022-01-11 15:56:29
【问题描述】:

我收到错误消息,由于 graphql-js 的依赖性,无法编译 graphql。

Version: webpack 4.43.0
Time: 69237ms
Built at: 01/12/2021 3:01:04 PM
 35 assets
Entrypoint main = assets/vendors~896.bundle.js assets/page.js

ERROR in ./node_modules/graphql/index.mjs 12:0-65:205
Can't reexport the named export 'BREAK' from non EcmaScript module (only default export is available)
 @ ./node_modules/graphql-tag/lib/index.js
 @ ./node_modules/apollo-boost/lib/bundle.esm.js
 @ ./src/apollo/client.ts
 @ ./src/App.tsx
 @ ./src/client.js

ERROR in ./node_modules/graphql/index.mjs 20:0-87:42
Can't reexport the named export 'SAMPLE' from non EcmaScript module (only default export is available)
 @ ./node_modules/graphql-tag/lib/index.js
 @ ./node_modules/apollo-boost/lib/bundle.esm.js
 @ ./src/apollo/client.ts
 @ ./src/App.tsx
 @ ./src/client.js

ERROR in ./node_modules/graphql/index.mjs 99:0-80:50
Can't reexport the named export 'SAMPLE' from non EcmaScript module (only default export is available)
 @ ./node_modules/graphql-tag/lib/index.js
 @ ./src/apollo/client.ts
 @ ./src/App.tsx
 @ ./src/client.js

错误:无法从非 EcmaScript 模块重新导出命名导出“BREAK”(只有默认导出可用)

还有一百万以上。
附言。如果您需要更多详细信息,请告诉我

【问题讨论】:

  • 你是如何在client.js中导入的?
  • @Andrei,只使用导入

标签: webpack graphql apollo apollo-client


【解决方案1】:

我昨天遇到了同样的问题,并关注了this answer from github,我将'.mjs' 添加到我的configureWebpack 扩展中。并遵守规则。只要确保出现在.js' 之前。 所以基本上你会得到如下:

const config = {
 configureWebpack: {
   resolve: { // .mjs comes before .js 
     extensions: ['*', '.mjs', '.js', '.json', '.gql', '.graphql']
   },
   module: {
     rules: [ 
       {
         test: /\.mjs$/,
         include: /node_modules/,
         type: 'javascript/auto'
       },
       // all the other rules
     ]
   }
 }
}

module.exports = config

【讨论】:

  • 谢谢。解决了问题
【解决方案2】:

尝试使用require(“module”),或者如果您是这样做的,您应该尝试使用import("module")。也许这会有所帮助。

【讨论】:

    猜你喜欢
    • 2017-08-21
    • 2016-10-20
    • 2016-07-01
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 2016-10-24
    相关资源
    最近更新 更多