最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

【已解决】ant-design-mobile配置webpack出错:configuration.resolve has an unknown property modulesDirectories

Webpack crifan 370浏览 0评论

折腾:

【记录】去试用Ant Design的UI

期间,参考

ant-design-mobile/introduce.en-US.md at master · ant-design/ant-design-mobile

安装

去配置了:

/webpack.config.babel.js

    modulesDirectories: [‘node_modules’, path.join(__dirname, ‘../node_modules’)],
    extensions: [”, ‘.web.js’, ‘.jsx’, ‘.js’, ‘.json’, ‘.less’],

相关的部分是:

module.exports = {
  context: path.resolve(__dirname, “src”),
  entry: [‘babel-polyfill’, ‘./index.js’],
  output: {
    path: path.resolve(__dirname, “build”),
    // publicPath: ‘/’,
    publicPath: ‘/uapp/’,
    // publicPath: ‘./uapp/’,
    // filename: ‘bundle.js’
    filename: ‘bundle_[hash].js’
  },
  resolve: {
    modulesDirectories: [‘node_modules’, path.join(__dirname, ‘../node_modules’)],
    extensions: [”, ‘.web.js’, ‘.jsx’, ‘.js’, ‘.json’, ‘.less’],
    modules: [
      path.resolve(__dirname, “src/lib”),
      path.resolve(__dirname, “node_modules”),
      ‘node_modules’
    ],
    alias: {
      components: path.resolve(__dirname, “src/components”),    // used for tests
      style: path.resolve(__dirname, “src/style”),
      ‘react’: ‘preact-compat’,
      ‘react-dom’: ‘preact-compat’
    }
  },
。。。

结果npm run dev出错:

➜  ucowsapp git:(master) ✗ npm run dev
> ucows-app@6.0.0 dev /Users/crifan/dev/dev_root/daryun/。。。ucowsapp/ucowsapp
> cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
– configuration.resolve has an unknown property ‘modulesDirectories’. These properties are valid:
   object { alias?, aliasFields?, cachePredicate?, descriptionFiles?, enforceExtension?, enforceModuleExtension?, extensions?, fileSystem?, mainFields?, mainFiles?, moduleExtensions?, modules?, plugins?, resolver?, symlinks?, unsafeCache?, useSyncFileSystemCalls? }
– configuration.resolve.extensions[0] should not be empty.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ucows-app@6.0.0 dev: `cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ucows-app@6.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/crifan/.npm/_logs/2017-07-29T13_27_04_354Z-debug.log
➜  ucowsapp git:(master) ✗

configuration.resolve has an unknown property ‘modulesDirectories’

Issue with webpack configuration · Issue #1036 · AngularClass/angular-starter

Migrating to Webpack 2

// before
resolve: {
  modulesDirectories: […],
}
// after
resolve: {
  modules: […],
}

也和我猜的是类似的。

肯定是最新的语法修改了。

之前配置中已有的:

    modules: [
      path.resolve(__dirname, “src/lib”),
      path.resolve(__dirname, “node_modules”),
      ‘node_modules’
    ],

就已经包含了:

node_modules

所以,此处估计是无须再去配置了。

改为:

  resolve: {
    // modulesDirectories: [‘node_modules’, path.join(__dirname, ‘../node_modules’)],
    extensions: [”, ‘.web.js’, ‘.jsx’, ‘.js’, ‘.json’, ‘.less’],
    modules: [
      path.resolve(__dirname, “src/lib”),
      path.resolve(__dirname, “node_modules”),
      ‘node_modules’
    ],
    alias: {
      components: path.resolve(__dirname, “src/components”),    // used for tests
      style: path.resolve(__dirname, “src/style”),
      ‘react’: ‘preact-compat’,
      ‘react-dom’: ‘preact-compat’
    }
  },

结果解决了此问题。

转载请注明:在路上 » 【已解决】ant-design-mobile配置webpack出错:configuration.resolve has an unknown property modulesDirectories

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
62 queries in 0.252 seconds, using 12.04MB memory