我有一个弹出的 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/