vue 打包异常记录

包缺失

Error: Cannot find module 'webpack-merge'

npm install --save-dev webpack-merge 

Cannot find module 'extract-text-webpack-plugin'

cnpm install --save extract-text-webpack-plugin

const webpackConfig = merge(baseWebpackConfig, {
                      ^

TypeError: merge is not a function

cnpm i html-webpack-plugin@4.5.0 -D

ERROR in ./src/main.js
Module build failed (from ./node_modules/_babel-loader@7.1.1@babel-loader/lib/index.js):
Error: Cannot find module 'babel-plugin-component'
Require stack:

cnpm i babel-plugin-component -D

Error: Cannot find module '@vue/babel-preset-app'
Require stack:

cnpm i @vue/babel-preset-app -D

WARNING in ./src/icons/svg/ sync \.svg$ ./icon-admin.svg
Module not found: Error: Can't resolve 'svg-sprite-loader' in '

cnpm install stylus svg-sprite-loader --save-dev

Error: Cannot find module 'babel-preset-es2015'
Require stack:

cnpm i babel-preset-es2015 -D

Module not found: Error: Can't resolve 'vue-loader' i

cnpm i --save-dev babel-loader

Module build failed (from ./node_modules/_vue-loader@17.0.0@vue-loader/dist/index.js):
Error: Cannot find module 'vue/compiler-sfc'
Require stack:

npm i vue-loader@15 -D

TypeError: Cannot read properties of undefined (reading 'fileLoader')

cnpm i vue-loader@15 -D

    compiler.hooks.thisCompilation.tap(pluginName, compilation => {
                   ^

TypeError: Cannot read properties of undefined (reading 'thisCompilation')

npm uninstall compression-webpack-plugin

cnpm install --save-dev compression-webpack-plugin@1.1.11

A common cause of this error is the presence of a configuration options object without the corresponding preset name. Example:

Invalid:
  `{ presets: [{option: value}] }`
Valid:
  `{ presets: [['presetName', {option: value}]] }`

cnpm install --save-dev babel-core@7.0.0-bridge.0

ERROR in ./src/main.js
Module build failed: Error: Couldn't find preset "@babel/react" relative to directory

cnpm install --save-dev html-webpack-plugin

D:\ITEM\chembull\Code\web-admin-ui\node_modules\_html-webpack-plugin@5.5.0@html-webpack-plugin\index.js:40
    compiler.hooks.initialize.tap('HtmlWebpackPlugin', () => {
                   ^

TypeError: Cannot read properties of undefined (reading 'initialize')

cnpm install --save-dev html-webpack-plugin@^3.2.0

语法错误

 component lists rendered with v-for should have explicit keys.

v-for需要加上:key

 v-for="(item,index) in labelList" :key="index"

module.exports = merge(prodEnv, {
                 ^

TypeError: merge is not a function

const merge = require('webpack-merge')

修改为

const {merge}= require('webpack-merge')

配置文件错误


ERROR in multi main
Module not found: Error: Cannot resolve module '\src\main.js' inadmin-ui
 @ multi main

ERROR in multi main
Module not found: Error: Cannot resolve module 'babel-polyfill' in 
 @ multi main

resolve: {    extensions: ['', '.es6'']} 增加空格

    new webpack.HashedModuleIdsPlugin(),
    ^

TypeError: webpack.HashedModuleIdsPlugin is not a constructor

注释new webpack.HashedModuleIdsPlugin(), 

module.exports中增加

optimization: { moduleIds: 'named'  },

    new webpack.optimize.ModuleConcatenationPlugin(),
    ^

TypeError: webpack.optimize.ModuleConcatenationPlugin is not a constructor

   注释 new webpack.optimize.ModuleConcatenationPlugin(),

    compiler.hooks.make.tapAsync(
                   ^

TypeError: Cannot read properties of undefined (reading 'make')

注释掉 new webpack.optimize.CommonsChunkPlugin 

    throw new _ValidationError.default(errors, schema, configuration);
    ^

ValidationError: Invalid options object. Copy Plugin has been initialized using an options object that does not match the API schema.
 - options.patterns[0] has an unknown property 'ignore'. These properties are valid:

 new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, '../static'),
        to: config.build.assetsSubDirectory,
        ignore: ['.*']
      }
    ])

改成

    new CopyWebpackPlugin({
      patterns:[{
        from: path.resolve(__dirname, '../static'),
        to: config.build.assetsSubDirectory,
        //ignore: ['.*'],
        }]
      })

> webpack --progress --config build/webpack.prod.conf.js

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.optimization.splitChunks should be one of these:
   false | object { automaticNameDelimiter?, cacheGroups?, chunks?, defaultSizeTypes?, enforceSizeThreshold?, fallbackCacheGroup?, filename?, hidePathInfo?, maxAsyncRequests?, maxAsyncSize?, maxInitialRequests?, maxInitialSize?, maxSize?, minChunks?, minRemainingSize?, minSize?, minSizeReduction?, name?, usedExports? }
   -> Optimize duplication and caching by splitting chunks by shared modules and cache group.
   Details:
    * configuration.optimization.splitChunks.name should be one of these:
      false | string | function
      -> Give chunks created a name (chunks with equal name are merged).
      Details:
       * configuration.optimization.splitChunks.name should be false.
       * configuration.optimization.splitChunks.name should be a string.
       * configuration.optimization.splitChunks.name should be an instance of function.

重写

optimization: {
    minimizer: [
       new UglifyJsPlugin({
        exclude: /\.min\.js$/,  
        cache: true,
        parallel: true, // 开启并行压缩,充分利用cpu
        sourceMap: false,
        extractComments: false, // 移除注释
        uglifyOptions: {
          compress: {
            unused: true,
            warnings: false,
            drop_debugger: true
          },
          output: { comments: false }
        }
      }), 
      new OptimizeCssAssetsPlugin({
        assetNameRegExp: /\.css$/g,
        cssProcessorOptions: {
          safe: true,
          autoprefixer: { disable: true },
          mergeLonghand: false,
          discardComments: {
            removeAll: true // 移除注释
          }
        },
        canPrint: true
      })
    ]
  },
 

[webpack-cli] TypeError: compiler.plugin is not a function
    at ExtractTextPlugin.apply  

移除 extract-text-webpack-plugin插件后,安装mini-css-extract-plugin

配置webpack.config

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
{
  test:/\.css$/,
  use:[MiniCssExtractPlugin.loader,'css-loader']
}

 
new MiniCssExtractPlugin({
  filename: '[name].css',
  chunkFilename: "[id].css"
})

    throw new Error('"' + sortMode + '" is not a valid chunk sort mode');
    ^

Error: "dependency" is not a valid chunk sort mode

 chunksSortMode: 'dependency'
 改成     chunksSortMode: 'auto'

Module parse failed: Unexpected character '@'

cnpm install stylus babel-plugin-transform-decorators-legacy --save-dev

.babelrc(可能会集成在其他文件)修改{

"presets": ["es2015"], "

plugins": ["transform-decorators-legacy"] }

they need separate names, e.g.

  plugins: [
    ['some-plugin', {}],
    ['some-plugin', {}, 'some unique name'],
  ]

Duplicates detected are:

根据 Duplicates detected are: 提示删除package.json重复的插件

 Using removed Babel 5 option: .modules 
- Use the corresponding module transform plugin in the `plugins` option. 
Check out http://babeljs.io/docs/plugins/#modules

删除presets中的module


Error: Cannot use the decorators and decorators-legacy plugin together  

删除 plugins  中的 transform-decorators-legacy

ERROR in static/js/6533.js from UglifyJs
`warnings` is not a supported option

optimization.minimizer  UglifyJsPlugin语法有变。

new UglifyJsPlugin({
        exclude: /\.min\.js$/, 
        cache: true,
        parallel: true,  
        sourceMap: false,
        extractComments: false,  
        warnings: false,
        uglifyOptions: {
          compress: { 

           warnings: false,//原始位置
            unused: true,
            drop_debugger: true
          },
          output: {
            comments: false
          }
        }
      }),

Module parse failed: Unexpected token (2:2)
File was processed with these loaders:
 * ./node_modules/_vue-loader@17.0.0@vue-loader/dist/index.js
You may need an additional loader to handle the result of these loaders.

style不识别,配置没加载出来,有个教程让我把代码注释掉了,下面这段代码就是

const ExtractTextPlugin = require('extract-text-webpack-plugin')
ExtractTextPlugin.extract({use: 'css-loader',  fallback: 'vue-style-loader'})

vue 中的style不能识别​​​​​​webpack配置打包支持scss、自动import全局文件、分享变量、单独提取css文件、自动生成HTML页面_A-Tione的博客-CSDN博客

[webpack-cli] Invalid options object. Compression Plugin has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'asset'. These properties are valid:
   object { test?, include?, exclude?, algorithm?, compressionOptions?, threshold?, minRatio?, deleteOriginalAssets?, filename? }

webpack.prod.conf.js ,将 assert 修改为 filename: '[path][base].gz',// 整个复制,值格式也变了

asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
This can impact web performance.

module.exports下增加

     performance: {
          hints:'warning',
            //入口起点的最大体积 整数类型(以字节为单位)
            maxEntrypointSize: 50000000,
              //生成文件的最大体积 整数类型(以字节为单位 300k)
              maxAssetSize: 500000000,
                //只给出 js 文件的性能提示
                assetFilter: function(assetFilename) {
                  return assetFilename.endsWith('.js');
                }
        } , 

warning  The "components" property should be above the "template" property on

书写顺序有误,改下文件下的属性顺序(泥马真不明白,这bug怎么设计的也不修复)

WARNING

DefinePlugin
Conflicting values for 'process.env.NODE_ENV'

module.exports .optimization.  下增加  nodeEnv: false,

Module build failed: Error: .plugins[1][1] must be an object, false, or undefined

  "plugins": ["transform-runtime", ["component", [     {       "libraryName": "element-ui"     }   ]]],

改成

"plugins": ["transform-runtime",
  ["component", {
            "libraryName": "mint-ui",
            "style": true
        }]

  ],


ERROR in ./src/main.js
Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In D:\ITEM\chembull\Code\web-admin-ui\node_modules\_babel-preset-stage-2@6.24.1@babel-preset-stage-2\lib\index.js

    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-0": "^6.24.1",

版本号替换

Module build failed (from ./node_modules/_vue-loader@13.3.0@vue-loader/index.js):
TypeError: Cannot read properties of undefined (reading 'vue')

package.json 或者.babelrc 中添加 "presets":[ "@vue/app"]

Error: Multiple configuration files found. Please remove one:
 - package.json
 - D:\ITEM\chembull\Code\web-admin-ui\.babelrc

package和,babelrc配置重复,移除一个

This API has been removed. 
If you're looking for this functionality in Babel 7, 
you should import the '@babel/helper-module-imports' 
module and use the functions exposed  from that module, s
uch as 'addNamed' or 'addDefault'.

cnpm cache verify
cnpm install

删除 node_modules

npm run build



webpackJsonp is not defined

webpackJsonp is not defined - WayneLiu123 - 博客园


[10:31:14] Error: File not found with singular glob: D:\ITEM\chembull\Code\web-admin-ui\dist/202204281030/static/js/manifest.js (if this was purposeful, use `allowEmpty` option)

搜索manifest.js,在出现的位置增加: {allowEmpty: true}

例子:gulp.src(`${versionPath}/static/js/manifest.js`, {allowEmpty: true})

ERROR in ./node_modules/_css-loader@0.28.11@css-loader?{"sourceMap":false}!./node_modules/_vue-loader@13.3.0@vue-loader/lib/style-compiler?{"vue":true,"id":"data-v-d2550552","scoped":true,"hasInlineConfig":false}!./node_modules/_sass-loader@8.0.0@sass-loader/dist/cjs.js?{"sourceMap":false}!./node_modules/_vue-loader@13.3.0@vue-loader/lib/selector.js?type=styles&index=0!.




Module build failed: TypeError: this.getResolve is not a function
    at Object.loader 

卸载版本 npm uninstall sass-loader

安装 npm install sass-loader@7.3.1 --save-dev

'webpack' 不是内部或外部命令,也不是可运行的程序be created: Error: EPERM: operation not permitted, open 'D:\Program Fil

安装一下,如果package.json已经有了,还显示,复制出版本号再装一遍

cnpm install webpack@3.11.0

Error: Cannot find module 'webpack-node-externals'

Cnpm install webpack-node-externals

Module build failed: TypeError: this.getResolve is not a function

 npm install sass-loader@7.3.1 --save-dev

Server-side bundle should have one single entry file. Avoid using CommonsChunkPlugin in the server config.

webpack3            new webpack.optimize.CommonsChunkPlugin  注释

webpack4        optimization: {splitChunks:   false}

Module build failed: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin,

webpack.conf.js

 const ExtractTextPlugin = require('extract-text-webpack-plugin')

    new ExtractTextPlugin({
      filename: utils.assetsPath('css/[name].css'),
      // set the following option to `true` if you want to extract CSS from
      // codesplit chunks into this main css file as well.
      // This will result in *all* of your app's CSS being loaded upfront.
      allChunks: false,
    }),

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 在 Vue 中,您可以使用 try-catch 语句来捕获异常。例如: ``` try { // 这里写可能会出现异常的代码 } catch (error) { // 这里写处理异常的代码 // 例如,将异常信息记录到 txt 文件中 const fs = require('fs') fs.appendFileSync('error.txt', error) } ``` 在这段代码中,try 块中的代码是可能会出现异常的代码,如果出现异常,则会跳转到 catch 块中处理异常。在 catch 块中,我们可以使用 node.js 中的 fs 模块来将异常信息记录到 txt 文件中。 需要注意的是,Vue 是一个前端框架,并不能直接使用 node.js 中的 fs 模块。如果要在 Vue 中使用 fs 模块,您需要将 Vue 项目打包成服务器端渲染 (SSR) 应用,或者使用 Webpack 等工具将 Vue 项目打包成后端代码。 ### 回答2: 在Vue中,要将异常记录到txt文件,我们可以使用JavaScript的File API和Blob对象来实现。 首先,我们需要在Vue实例中定义一个方法来处理异常,并将异常信息写入txt文件: ```javascript methods: { logError(error) { // 创建一个Blob对象,将异常信息写入其中 const blob = new Blob([error.stack], { type: 'text/plain' }); // 创建一个临时a标签,用于下载txt文件 const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'error_log.txt'; // 将a标签添加到DOM中,并模拟点击下载 document.body.appendChild(link); link.click(); document.body.removeChild(link); } } ``` 然后,在需要捕获异常的地方使用try...catch语句来捕获异常,并调用logError方法将异常信息写入txt文件: ```javascript try { // ... 可能会产生异常的代码 } catch (error) { this.logError(error); } ``` 当代码中产生异常时,logError方法会将异常信息写入txt文件,并自动下载到本地。用户可以根据需要进行文件命名和存储路径的修改。 需要注意的是,该方法仅适用于前端开发环境,如果需要在后端记录异常到txt文件,可以借助Node.js的fs模块来实现相似的功能。 ### 回答3: Vue 可以通过以下步骤将异常记录到一个 txt 文件中: 1. 创建一个全局错误处理器,在 Vue 根实例的 `main.js` 文件中: ```javascript Vue.config.errorHandler = function (err, vm, info) { // 将错误信息写入到txt文件 // 参数err为错误对象,vm为Vue组件实例,info为错误信息(可选) // 可以调用一个自定义的函数writeErrorToTxt来将错误信息写入txt文件 writeErrorToTxt(err, vm, info) } ``` 2. 在写入错误信息到 txt 文件的函数 `writeErrorToTxt` 中: ```javascript function writeErrorToTxt(err, vm, info) { let errorDetails = { error: err.toString(), component: vm.$options.name, // 获取组件名称 info: info || '' // 为可选参数,用于提供额外的错误信息 } // 将错误信息转为 JSON 格式 let errorJSON = JSON.stringify(errorDetails, null, 2) // 创建一个新的 Blob 对象 let blob = new Blob([errorJSON], { type: 'text/plain' }) // 创建一个 a 标签,并设置点击事件,实现文件下载 let a = document.createElement('a') a.href = URL.createObjectURL(blob) a.download = 'error.txt' a.click() } ``` 3. 在 Vue 组件中出现异常时,错误会被全局错误处理器捕捉到,并调用 `writeErrorToTxt` 函数将错误信息写入 txt 文件。用户可以点击下载该文件以查看错误信息。 请注意,这种记录异常到 txt 文件的方法适用于开发环境和生产环境。但对于生产环境,应考虑将错误信息发送到服务器或其他日志记录系统,以便更好地追踪和处理错误。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤独白鲸

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值