Babel / Webpack:找不到“yaml-loader”(在开发中工作,而不是生产)

时间:2018-02-05 13:02:50

标签: javascript node.js webpack babeljs

这是令人讨厌的代码行:

import Channel from '!json-loader!yaml-loader!../../../../config/channel.yml'

如您所见,我正在使用!来绕过正常的导入加载器逻辑,因此我可以在编译时将解析后的YAML文件作为局部变量导入。

这在开发中非常有效(使用webpack-dev-server)但在生产中失败:

Module not found: Error: Can't resolve 'yaml-loader' in '/var/www/www.avfacts.org/releases/20180205125420/app/frontend/views/Episodes'
 @ /var/www/www.avfacts.org/shared/node_modules/babel-loader/lib!/var/www/www.avfacts.org/shared/node_modules/vue-loader/lib/selector.js?type=script&index=0!./app/frontend/views/Episodes/Form.vue 87:0-78
 @ ./app/frontend/views/Episodes/Form.vue
 @ /var/www/www.avfacts.org/shared/node_modules/babel-loader/lib!/var/www/www.avfacts.org/shared/node_modules/vue-loader/lib/selector.js?type=script&index=0!./app/frontend/views/Episodes/Edit.vue
 @ ./app/frontend/views/Episodes/Edit.vue
 @ ./app/frontend/routes.js
 @ ./app/frontend/packs/application.js

这是我的package.json文件:

{
  "name": "avfacts",
  "private": true,
  "dependencies": {
    "@panter/vue-i18next": "^0.9.1",
    "@rails/webpacker": "^3.2.1",
    "axios": "^0.17.1",
    "babel-polyfill": "^6.26.0",
    "babel-preset-minify": "^0.2.0",
    "i18next": "^10.3.0",
    "lodash": "^4.17.4",
    "luxon": "^0.4.0",
    "marked": "^0.3.12",
    "moment": "^2.20.1",
    "moment-duration-format": "^2.2.1",
    "normalize.css": "^7.0.0",
    "numeral": "^2.0.6",
    "precss": "^3.1.0",
    "simplemde": "^1.11.2",
    "vue": "^2.5.13",
    "vue-datetime": "^1.0.0-beta.2",
    "vue-loader": "^13.7.0",
    "vue-router": "^3.0.1",
    "vue-template-compiler": "^2.5.13",
    "vuex": "^3.0.1",
    "weekstart": "^1.0.0"
  },
  "devDependencies": {
    "babel-plugin-transform-async-to-generator": "^6.24.1",
    "webpack-dev-server": "^2.11.1",
    "yaml-loader": "^0.5.0"
  }
}

(是的,我确实尝试将yaml-loadersdevDependencies移到dependencies,即使这不起作用,但确实无法正常工作)

2 个答案:

答案 0 :(得分:1)

您是否在webpack.config.js中添加了加载程序。

// webpack.config.js

module: {
  loaders: [
    {
      test: /\.yaml$/,
      include: path.resolve('data'),
      loader: 'yaml',
    },
  ],
}

正如https://www.npmjs.com/package/yaml-loader

中提到的那样

答案 1 :(得分:0)

编辑:不,那不是。我用yaml-js-loader取代了yaml-loader,并称它为一天。仍然不确定问题是什么。

这个问题似乎通过在我的require 'capistrano/rails/assets中禁用Capfile来解决,从而禁用了正常的Rails Sprockets资产编译(此任务也运行yarn install,但显然是在不同的环境中或某事?)。

现在只运行capistrano/yarn个任务,成功执行Webpack资产编译。