Importing json files result in SyntaxError: Unexpected token m in JSON at position 0
See original GitHub issue💥 Regression Report
After upgrade of jest-runtime to 24.8.0 the json file import stopped working because the json file is not imported but transformed into following string
module.exports = "permanentComponentConfigurations.json";
As a workaround I provided a json transformation like so
package.json
"transform": {
".+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
".+\\.css$": "<rootDir>/config/jest/cssTransform.js",
".+\\.json": "<rootDir>/config/jest/jsonTransform.js",
"(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
(The configuration from package.json is based on Create-React-App)
jsonTransform.js
module.exports = {
process(src) {
return src;
}
};
Last working version
Worked up to version: 24.7.1
Stopped working in version: 24.8.0
To Reproduce
Import a json file in js like
import PERMANENT_CONFIGURATIONS from 'core/service/config/permanentComponentConfigurations.json';
With 24.8.0 json files are transformed as well. But the resulting json file import results to following content
module.exports = "permanentComponentConfigurations.json";
Expected behavior
The imported json file should be JSON.parsed like before with 24.7.1 per default. If someone needs custom transformation, providing a transformation file is fine, but it should not be a requirement.
Link to repl or repo (highly encouraged)
Please provide either a repl.it demo or a minimal repository on GitHub.
Issues without a reproduction link are likely to stall.
Run npx envinfo --preset jest
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Xeon(R) CPU E3-1226 v3 @ 3.30GHz
Binaries:
Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (2 by maintainers)

Top Related StackOverflow Question
just a small addition for people accidentally stepping over this:
if you’ve been using
28.8 was a breaking change as it will break your json imports. You might want to e.g. restrict the transform to only transform js files.
@sakulstra After 3 hours of debugging, I must say… You saved my day! I’m almost in tears !!!