Error in resolving json module
See original GitHub issueDescription
Using "resolveJsonModule": true in tsconfig.json results in import error after compilation.
The reason is that the .json extension is removed.
Expected Behavior
import data from './src/data.json' => import data from './src/data.json'
import data from '@src/data.json' => import data from './src/data.json'
Actual Behavior
import data from './src/data.json' => import data from './src/data'
import data from '@src/data.json' => import data from './src/data'
Version ├─ ttypescript@1.5.12 ├─ typescript-transform-paths@2.2.2 └─ typescript@4.1.3
Config
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"baseUrl": ".",
"paths": {
"@*": ["src/*"]
},
"plugins": [
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
},
"files": ["src/index.ts"]
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Option resolveJsonModule doesn't work without ... - GitHub
Confirmed that setting resolveJsonModule to true in my tsconfig.json resolved this issue. 26
Read more >resolveJsonModule not functioning with Angular 10?
I got this additional error message: Cannot find module 'nameOfMyJsonFile.json'. Consider using '--resolveJsonModule' to import module with '.
Read more >Solved: "Cannot find module 'x.json'" TypeScript Error
When trying to import a JSON file in your TypeScript project, you may see the following error: Cannot find module 'my-json-file.json'.
Read more >Common TypeScript module problems and how to solve them
Solution 2: Locate the module and resolve imports ; "*" value in the array means the exact name of the module, while the...
Read more >Resolve JSON files as modules in TypeScript - Koen Woortman
If you would try to import a JSON file you can expect an error message like: "Cannot find module './package.json'.
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 Free
Top 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

Fixed in v2.2.3
Ok. Thanks! I’ll have a look over the require specs and compiler to see. I’m not sure about that either.
@EmCeeEs I’m out for the rest of this week but will try to get it wrapped next week! In the mean time you can use the
@transform-pathtag to manually transform.