Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

[Bug Report] raw-loader failed to load *.json #91

Open
ulivz opened this issue Apr 19, 2020 · 2 comments
Open

[Bug Report] raw-loader failed to load *.json #91

ulivz opened this issue Apr 19, 2020 · 2 comments

Comments

@ulivz
Copy link

ulivz commented Apr 19, 2020

  • 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:

  1. git clone https://github.com/ulivz/raw-loader-load-json-repro
  2. yarn
  3. npx webpack
  4. You'll got following error:

  1. Modify entry index.js,comment json import and uncomment js import:
- 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.

@alexander-akait
Copy link
Member

alexander-akait commented Apr 20, 2020

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'
}

@alexander-akait
Copy link
Member

alexander-akait commented Jun 24, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants