Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack - Cannot find module raw-loader

I need to load a JS file as a string so I can run some analysis on it. I am trying to use raw-loader with Webpack (2.2.0).

I get: 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:

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

raw-loader is in my package.json for the project. It is present in my node modules. I've blown-away my node_modules and have reinstalled. I've looked at many solutions and nothing seems to point to a fix.

like image 969
Diodeus - James MacFarlane Avatar asked Nov 15 '22 23:11

Diodeus - James MacFarlane


1 Answers

You have an error in your regexp pattern.

You are using \a which matches the bell character (ASCII 7)

And . matches any character, you need to escape it.

Moreover, using both use and loader is misleading. You should use only one - see this answer: 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'
      }
    ]
  }
}
like image 117
lavor Avatar answered Nov 30 '22 23:11

lavor