webpack - 错误 : Should not import the named export 'version' (imported as 'version' )

标签 webpack webpack-5

我有一个弹出的 create-react-app 项目。将其更新到 webpack 5 后,我收到此错误。它在 webpack v4.41.5 上运行良好
节点 v10.23.0
操作系统:MacOS Catalina 10.15.7

Error: Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon),Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)


我正在使用以下 webpack 配置:
{ mode: 'production',
  bail: true,
  devtool: 'source-map',
  entry:
   [ '/Users/Homeoffice/Documents/toolbox-frontend-clone2/src/index.js' ],
  output:
   { path: '/Users/Homeoffice/Documents/toolbox-frontend-clone2/build',
     pathinfo: false,
     filename: 'static/js/[name].[contenthash:8].js',
     chunkFilename: 'static/js/[name].[contenthash:8].chunk.js',
     publicPath: '/',
     devtoolModuleFilenameTemplate: [Function],
     globalObject: 'this' },
  optimization:
   { minimize: false,
     minimizer: [ [TerserPlugin], [OptimizeCssAssetsWebpackPlugin] ],
     splitChunks: { chunks: 'all', name: false },
     runtimeChunk: { name: [Function: name] } },
  resolve:
   { modules:
      [ 'node_modules',
        '/Users/Homeoffice/Documents/toolbox-frontend-clone2/node_modules' ],
     extensions:
      [ '.web.mjs', '.mjs', '.web.js', '.js', '.json', '.web.jsx', '.jsx' ],
     alias: { 'react-native': 'react-native-web' },
     plugins: [ [Object], [ModuleScopePlugin] ] },
  resolveLoader: { plugins: [ [Object] ] },
  module: { strictExportPresence: true, rules: [ [Object] ] },
  plugins:
   [ HtmlWebpackPlugin { userOptions: [Object], version: 5 },
     InlineChunkHtmlPlugin { htmlWebpackPlugin: [Function], tests: [Array] },
     InterpolateHtmlPlugin { htmlWebpackPlugin: [Function], replacements: [Object] },
     ModuleNotFoundPlugin {
       appPath: '/Users/Homeoffice/Documents/toolbox-frontend-clone2',
       yarnLockFile: undefined,
       useYarnCommand: [Function: bound useYarnCommand],
       getRelativePath: [Function: bound getRelativePath],
       prettierError: [Function: bound prettierError] },
     DefinePlugin { definitions: [Object] },
     MiniCssExtractPlugin { options: [Object], runtimeOptions: [Object] },
     ManifestPlugin { opts: [Object] },
     IgnorePlugin {
       options: /^\.\/locale$/,
       checkIgnore: [Function: bound checkIgnore] },
     GenerateSW { config: [Object] },
     [Function] ],
  node: false,
  performance: false }

最佳答案

改变以下

import { version } from '../../package.json';

import packageInfo from '../../package.json';
然后从类似的东西更改您的访问权限
  version,
或者
  version: version,
version: packageInfo.version,

关于webpack - 错误 : Should not import the named export 'version' (imported as 'version' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64993118/

相关文章:

node.js - 使用 React 和 Node 破坏浏览器缓存

webpack - 路径连接在 webpack 5 中不起作用,但在 webpack 4 中起作用

javascript - 使用 webpack 5 将 SVG 导入为 React 组件

javascript - Webpack:抑制来自特定文件的警告

javascript - 在 React-Boilerplate 中使用 Firebase 身份验证时,服务工作线程捕获对 Google 的 __/auth 请求

webpack - 如何在 Visual Studio 项目中通过 Webpack 使用 Aurelia 中的监视/热重载?

javascript - Assets 文件夹中的图像未加载我收到 304 错误

less - 评估函数时出错 `ceil` : argument must be a number

Webpack - 错误 : Cannot find module 'node:assert'

javascript - webpack 中的 url-loader 配置正在从 React JS 项目中的不同路径加载图像