简体   繁体   English

Webpack - 找不到模块 raw-loader

[英]Webpack - Cannot find module raw-loader

I need to load a JS file as a string so I can run some analysis on it.我需要将 JS 文件作为字符串加载,以便对其进行一些分析。 I am trying to use raw-loader with Webpack (2.2.0).我正在尝试将 raw-loader 与 Webpack (2.2.0) 一起使用。

I get: Cannot find module 'raw-loader.../我得到: Cannot find module 'raw-loader.../

I've tried (yes, the path is correct):我试过(是的,路径是正确的):

let app = require('raw-loader!../../app.js').default;

let app = require('!!raw-loader!../../app.js').default;

I've even tried it without inline.我什至尝试过没有内联。 Raw-loader doesn't get engaged, it just tried to load the JS file normally: raw-loader 没有参与,它只是尝试正常加载 JS 文件:

module.exports = {
  module: {
    rules: [
      {
        test: /\app.js$/i,
        use: 'raw-loader',
        loader: 'raw-loader',
      }
    ]
  }
}

raw-loader is in my package.json for the project. raw-loader 在我的 package.json 项目中。 It is present in my node modules.它存在于我的节点模块中。 I've blown-away my node_modules and have reinstalled.我已经炸毁了我的 node_modules 并重新安装了。 I've looked at many solutions and nothing seems to point to a fix.我查看了许多解决方案,但似乎没有任何问题可以解决。

You have an error in your regexp pattern.您的正则表达式模式有错误。

You are using \a which matches the bell character (ASCII 7)您正在使用与铃铛字符匹配的\a (ASCII 7)

And .. matches any character, you need to escape it.匹配任何字符,您需要对其进行转义。

Moreover, using both use and loader is misleading.此外,同时useloader具有误导性。 You should use only one - see this answer: When do I use 'use' and 'loader' in Webpack 2 module.rules?您应该只使用一个 - 请参阅此答案: When do I use 'use' and 'loader' in Webpack 2 module.rules?

Try to use:尝试使用:

module.exports = {
  module: {
    rules: [
      {
        test: /app\.js$/i,
        loader: 'raw-loader'
      }
    ]
  }
}

Firstly I would update webpack.首先我会更新 webpack。 The version that you are using is, currently, 2 major versions behind the latest release.当前,您使用的版本比最新版本落后 2 个主要版本。 Maybe the error messages have been improved, Also, you can see more info about the error running webpack --display-error-details .也许错误消息已得到改进,此外,您可以查看有关运行webpack --display-error-details

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM