question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import JSON file in symlinked dependency

See original GitHub issue

Description

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

https://github.com/iameli/create-react-app-json-bug

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
iamelicommented, Mar 26, 2017

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 of json-loader.

0reactions
Timercommented, Mar 27, 2017

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found