Cannot import JSON files from node_modules
mikkelrd opened this issue · 1 comments
mikkelrd commented
I have a node module with some color values stored in JSON that I want to consume in a SCSS file. When I use the normal Sass import syntax for JSON from node_modules paths like so,
@import '~@mymodule/styles/dist/colors.json';
I get the following build error from webpack.
ERROR in ./src/vars.scss (./node_modules/css-loader??ref--8-1!./node_modules/resolve-url-loader!./node_modules/sass-loader/lib/loader.js??ref--8-3!./src/vars.scss)
Module build failed (from ./node_modules/sass-loader/lib/loader.js):
@import '~@mymodule/styles/dist/colors.json';
^
Unable to find "~@mymodule/styles/dist/colors.json" from the following path(s): /Users/mdavis/repo/src/styles, /Users/mdavis/repo, /Users/mdavis/repo/src/styles, /Users/mdavis/repo/src. Check includePaths.
NOTE: @import '~@mymodule/styles/dist/globals.css';
works just fine.
pmowrer commented
Hi @mikkelrd!
Sorry to hear you're stuck! I unfortunately can't help you with this, other than let you know that we just released 4.0.0
, allowing you to define a custom resolver function. It essentially provides you full control of how files are looked up. I don't think you should necessarily need it to use it (most use-cases work out of the box), but if nothing else it could prove useful to debug the issue.