开发服务器已使用与 API 架构不匹配的选项对象进行初始化

发布于 2025-01-11 03:34:33 字数 1631 浏览 0 评论 0原文

将 Angular 8 升级到 9 后,我收到以下错误,

        An unhandled exception occurred: Invalid options object. Dev Server has been 
          initialized using an options object that does not match the API schema.
           - options has an unknown property 'contentBase'. These properties are 
          valid:
            object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, 
          headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, 
          liveReload?, magicHtml?, onAfterSetupMiddleware?, 
           See "/private/var/folders/fp/tmjy2_2j15s50f6qpyj6x6mm0000gr/T/ng- 
           xbMtW3/angular-errors.log" for further details.

从我读到的内容来看,我明白这与 webpack 有关 - 因为我没有 webpack 配置经验 - 我真的不知道从哪里开始。

这是我的 webpack.config.js

    'use strict';
const path = require('path');
const SpritesmithPlugin = require('webpack-spritesmith');

const plugins = [
  new SpritesmithPlugin({
    src: {
      cwd: path.resolve(__dirname, 'src/styles/icons'),
      glob: '*.png'
    },
    target: {
      image: path.resolve(__dirname, 'src/assets/images/sprite.png'),
      css: path.resolve(__dirname, 'src/styles/_ui-sprite.scss')
    },
    apiOptions: {
      cssImageRef: "assets\/images\/sprite.png",
      generateSpriteName: function (sprite) {
        return 'icon-' + path.basename(sprite, '.png');
      }
    }
  })
];

module.exports = {
  context: __dirname,
  mode: 'development',
  entry: {'doNotTouch': './doNotTouch.ts'},

  output: {
    path: __dirname,
    filename: '[name].js'
  },

  plugins: plugins,

  module: {
    rules: []
  }
};

I'm getting the following error after upgrading angular 8 to 9,

        An unhandled exception occurred: Invalid options object. Dev Server has been 
          initialized using an options object that does not match the API schema.
           - options has an unknown property 'contentBase'. These properties are 
          valid:
            object { allowedHosts?, bonjour?, client?, compress?, devMiddleware?, 
          headers?, historyApiFallback?, host?, hot?, http2?, https?, ipc?, 
          liveReload?, magicHtml?, onAfterSetupMiddleware?, 
           See "/private/var/folders/fp/tmjy2_2j15s50f6qpyj6x6mm0000gr/T/ng- 
           xbMtW3/angular-errors.log" for further details.

From what i've read i understood it's something to do with webpack - since i don't have experience with webpack configuration - i don't really know where to begin.

Here is my webpack.config.js

    'use strict';
const path = require('path');
const SpritesmithPlugin = require('webpack-spritesmith');

const plugins = [
  new SpritesmithPlugin({
    src: {
      cwd: path.resolve(__dirname, 'src/styles/icons'),
      glob: '*.png'
    },
    target: {
      image: path.resolve(__dirname, 'src/assets/images/sprite.png'),
      css: path.resolve(__dirname, 'src/styles/_ui-sprite.scss')
    },
    apiOptions: {
      cssImageRef: "assets\/images\/sprite.png",
      generateSpriteName: function (sprite) {
        return 'icon-' + path.basename(sprite, '.png');
      }
    }
  })
];

module.exports = {
  context: __dirname,
  mode: 'development',
  entry: {'doNotTouch': './doNotTouch.ts'},

  output: {
    path: __dirname,
    filename: '[name].js'
  },

  plugins: plugins,

  module: {
    rules: []
  }
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡写薰衣草的香 2025-01-18 03:34:33

这很可能与您在不同文件夹中下载的模块的版本冲突有关。

删除所有节点模块和 Web 包并重新安装它们。

It most likely has to do with conflicting versions of a module you downloaded on different folders.

Delete all your node modules and web packages and reinstall them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文