Unable to import JSON file in symlinked dependency
See original GitHub issueDescription
I’ve created a reproduction repro here.
You can use create-react-app to import JSON files just fine require("./file.json")
. This works just fine if the JSON file is within the create-react-app project’s folder.
This behavior doesn’t work, however, if the file being imported is a symlinked dependency in node_modules
. Webpack (or whatever) complains Module not found: 'json'
.
I first ran into the problem with a dependency that had been symlinked by Lerna.
The repro I submitted automatically creates a symlinked dependency in a postinstall
script.
Expected behavior
I should import the JSON file.
Actual behavior
Failed to compile.
Error in ../demo-dependency/index.js
Module not found: 'json' in /Users/eli/code/json-bug/demo-dependency
@ ../demo-dependency/index.js 2:13-35
Environment
Run these commands in the project folder and fill in their results:
> npm ls react-scripts
demo-app@0.1.0 /Users/eli/code/json-bug/demo-app
└── react-scripts@0.9.5
> node -v
v7.5.0
> npm -v
4.4.4
Operating system: macOS 10.11.3 Browser and version: n/a, compilation error
Reproducible Demo
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
React Native: npm link local dependency, unable to resolve ...
But it fails when I attempt to import the module by name: import { ActualModuleName } from 'react-native-actualmodulename'.
Read more >Resolve | webpack
When importing from an npm package, e.g. import * as D3 from 'd3' , this option will determine which fields in its package.json...
Read more >Config Files - Babel.js
Babel loads .babelrc.json files, or an equivalent one using the supported ... .babelrc files failed to apply to symlinked node_modules when people expected ......
Read more >How to import JSON files in ES modules (Node.js) - Stefan Judis
Option 1: Read and parse JSON files yourself The Node. js documentation advises to use the fs module and do the work of...
Read more >Configuring Jest
The configuration also can be stored in a JSON file as a plain object: ... This option tells Jest that all imported modules...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As a workaround, everything works fine if the symlinked dependency includes
json-loader
as one of its own dependencies. So the problem has something to do with the resolution ofjson-loader
.Hmm, this probably works with JSON but not if you require some different dep not present in your project.
Thanks for testing this specific case!