Error when resolving es6 module using paths in TypeScript code
See original GitHub issue🐛 Bug Report
The following TypeScript code
import * as employeeData from 'Source_Data/employee';
generates this error message
Cannot find module 'Source_Data/employee' from 'src/framework/module/header.ts'
Require stack:
src/framework/module/header.ts
src/framework/backend/jsonData.ts
test/unittest/backend/jsonData.ts
1 | import {uuid} from 'Source_ODS/uuid';
2 | //import * as employeeData from 'Source_Framework/data/employee';
> 3 | import * as employeeData from 'Source_Data/employee';
| ^
4 |
5 |
6 | /**
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
at Object.<anonymous> (src/framework/module/header.ts:3:1)
when using this paths
settings:
{
"extends": "./configs/tsconfig_base",
"compilerOptions": {
"paths": {
"Source_Modules/*": ["./src/modules/*"],
"Source_Framework/*": ["./src/framework/*"],
"Source_Data/*": ["./src/framework/data/*"],
"Source_ODS/*": ["./src/framework/ods/*"],
"Source_Vendor/*": ["./vendor/*"],
"CoreImg/*": ["./img/*"],
"jquery-ui/*": ["jquery-ui/ui/*"],
"jquery-ui-css/*": ["./vendor/jquery-ui/ui-lightness/*"],
"JQueryUIImg/*": ["./vendor/jquery-ui/ui-lightness/images/*"]
}
},
"compileOnSave": false,
"include": [
"src/**/*",
"test/unittest/**/*"
],
"exclude": [
"node_modules"
]
}
but when changing it to this
import * as employeeData from 'Source_Framework/data/employee';
it works as expected.
To Reproduce
The problem can be reproduced at will but I’m currently not able to extract it from a large production environment into a simple example.
Expected behavior
The code reporting an error should work the same way the workaround works as the module does exist.
Link to repo (highly encouraged)
Unfortunately not yet possible but working on it
Debug log:
envinfo
System:
OS: macOS 10.15.7
Node version: 14.15.0
Npm packages:
jest: 26.6.3
ts-jest: 26.4.4
typescript: 4.0.5
babel(optional):
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Error when resolving es6 module using paths in TypeScript ...
The code reporting an error should work the same way the workaround works as the module does exist. Link to repl or repo...
Read more >Documentation - Module Resolution
Module resolution is the process the compiler uses to figure out what an import ... import can be resolved relative to baseUrl ,...
Read more >eslint / typescript: Unable to resolve path to module
The import plugin doesn't know about the correct location of the TypeScript config and hence cannot resolve those paths.
Read more >Typescript – How to solve the problem with unresolved path ...
Generally, what should be done can be summarized as follows: Take a look into tsconfig.json and check if there are path aliases defined...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
json contains an "exports" field, in which case files within packages can only be accessed via the paths defined in "exports" . For...
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
If one is using TypeScript path mapping in the project and want to use jest,
moduleNameMapper
must be configured for jest to understand. It is like a bridge between TypeScript and Jest.ts-jest
provides 2 ways to help to make it easier to configure:via util: https://kulshekhar.github.io/ts-jest/user/config/ see path mapping section.
AST transformer to alter output: https://kulshekhar.github.io/ts-jest/user/config/astTransformers see public transformers section
@ahnpnl Thank you!