raw-loader
raw-loader copied to clipboard
[Bug Report] raw-loader failed to load *.json
- Operating System: OSX
- Node Version: v12.16.1
- NPM Version: 6.13.4
- webpack Version: 4.42.1
- raw-loader Version: 4.0.1
Expected Behavior
*.json should be loaded successfully with raw-loader like the *.js;
Actual Behavior
*.json cannot be loaded successfully.
Code
import foo from 'raw-loader!./foo.json' // don't work
// import foo from 'raw-loader!./foo.js' // work
export default {
foo,
}
How Do We Reproduce?
I just created a minimal reproduction repo: raw-loader-load-json-repro, and here're the reproduction steps:
git clone https://github.com/ulivz/raw-loader-load-json-reproyarnnpx webpack- You'll got following error:

- Modify entry
index.js,commentjsonimport and uncommentjsimport:
- import foo from 'raw-loader!./foo.json' // don't work
+ // import foo from 'raw-loader!./foo.json' // don't work
- // import foo from 'raw-loader!./foo.js' // work
+ import foo from 'raw-loader!./foo.js'
export default {
foo,
}
Ru-run npx webpack,the build will be success.
Webpack has built-in json loader and it automatically works on json extension.
Ideally it should be written:
import foo from '!!raw-loader!./foo.json'; // Disable all loader
but it is not work as expected.
Workaround - setup loader in the configuration file:
{
test: /\.json$/i,
type: "javascript/auto",
use: 'raw-loader'
}
Another example of usage:
import myJSON from "./test.json.raw!=!raw-loader!./test.json"
Say to webpack do not use test.json as json resource and loading this using raw-loader. But I think we should improve it.