SilurianYang / uni-simple-router

A simple, lightweight 'uni-app' routing plugin
https://v2.hhyang.cn/v2/
MIT License
748 stars 164 forks source link

uniapp cli项目引入uni-simple-router yarn serve 报错 #260

Closed haoxf closed 3 years ago

haoxf commented 3 years ago

问题描述 执行 yarn serve 报错:

 ERROR  ValidationError: Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.node should be one of these:
   false | object { __dirname?, __filename?, global? }
   -> Include polyfills or mocks for various node stuff.
   Details:
    * configuration.node has an unknown property 'setImmediate'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'process'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'dgram'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'fs'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'net'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'tls'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
    * configuration.node has an unknown property 'child_process'. These properties are valid:
      object { __dirname?, __filename?, global? }
      -> Options object for node compatibility features.
 - configuration.watchOptions.ignored[0] should be a non-empty string.
   -> A glob pattern for files that should be ignored from watching.

系统信息:

补充信息 uniapp cli项目只能使用 webpack 4, 而 uni-simple-router 用了 webpack 5. 问题可能是 webpack 版本不一致导致。

SilurianYang commented 3 years ago

这个和 uni-simple-router 没有任何关系吧 你的 vue.config.js 贴出来看看

haoxf commented 3 years ago

实测删除 uni-simple-router 依赖,改为本地源码引入,编译通过

haoxf commented 3 years ago

这个和 uni-simple-router 没有任何关系吧 你的 vue.config.js 贴出来看看

const UniReadPages = require('uni-read-pages')

module.exports = {
  chainWebpack: config => {
    config.plugins.delete('fork-ts-checker')
    // config.plugin('webpack-bundle-analyzer').use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  },
  configureWebpack: config => {
    if (process.env.UNI_PLATFORM === 'h5') {
      const tfPages = new UniReadPages({
        includes: ['path', 'name', 'aliasPath', 'redirect', 'meta'],
      })
      config.plugins.push(
        new tfPages.webpack.DefinePlugin({
          ROUTES: JSON.stringify(tfPages.routes),
        }),
      )
    }
  },
}
SilurianYang commented 3 years ago

应该是开发依赖下载后 webpack 版本不一致。导致你在vue.config.js使用 webpack api 不兼容的问题。 我后续把 package.json 下的 devDependenciesdependencies 去掉再发布。