美文网首页
vue-cli版本升级4.X到5.X问题

vue-cli版本升级4.X到5.X问题

作者: 陌小亓 | 来源:发表于2022-07-18 09:47 被阅读0次

    1. options has an unknown property 'overlay'

    client: {
        overlay: {
          
        }
    }
    

    2. webpack < 5 used to include polyfills for node.js core modules by default.

    This is no longer the case. Verify if you need this module and configure a polyfill for it.
    If you want to include a polyfill, you need to:

    • add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
    • install 'path-browserify'
      If you don't want to include a polyfill, you can use an empty module like this:
      resolve.fallback: { "path": false }
      按照报错提示在代码中添加相应配置即可: 先安装依赖npm install path-browserify
    configuareWebpack: {
        resolve: {
            alias: {
            },
            fallback:{
                path: require.resolve("path-browserify")
            }
        }
    }
    

    3.ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.

    • options has an unknown property 'after'. These properties are valid:
      object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, liveReload?, magicHtml?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, server?, setupExitSignals?, setupMiddlewares?, static?, watchFiles?, webSocketServer? }

    经查阅官方文档webpack5-devServer,after和before已弃用,分别用middlewares.pushmiddlewares.unshift替代

    devServer: {
        setupMiddlewares: (middlewares, devServer) => {
          if (!devServer) {
            throw new Error('webpack-dev-server is not defined');
          }
    
          devServer.app.get('/setup-middleware/some/path', (_, response) => {
            response.send('setup-middlewares option GET');
          });
        }
    }
    

    4. devServer获取post传递参数undefined

    以前的写法

    // 安装 body-parser
    npm install body-parser
    const bodyParser = require(‘body-parser’);
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({
        extended: true
    }));
    

    express 4.X版本不需要额外加载body-parser

    const express = require(‘express’);
    devServer.app.use(express.json());
    devServer.app.use(express.urlencoded({
        extended: true
    }));
    

    相关文章

      网友评论

          本文标题:vue-cli版本升级4.X到5.X问题

          本文链接:https://www.haomeiwen.com/subject/yivrirtx.html