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.

Error in resolving json module

See original GitHub issue

Description 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:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
nonaracommented, Feb 2, 2021

Fixed in v2.2.3

1reaction
nonaracommented, Jan 28, 2021

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-path tag to manually transform.

Read more comments on GitHub >

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

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