[Bug]: Enum with path alias throws error: Could not locate module @foo/bar mapped as
See original GitHub issueVersion
27.0.7
Steps to reproduce
- Clone this repo: https://github.com/xyxc0673/test-ts-jest
- yarn
- yarn test
Expected behavior
all tests pass
Actual behavior
Configuration error:
Could not locate module @foo/bar mapped as:
/Users/carl/workspace/tests/ts-jest/examples/react/foo/$1.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/^@foo\/(.*)$/": "/Users/carl/workspace/tests/ts-jest/examples/react/foo/$1"
},
"resolver": undefined
}
> 1 | import { BarInterface, BarEnum } from "@foo/bar"
| ^
2 |
3 | export const testEnum = () => {
4 | const a: BarInterface = {
at createNoMappedModuleFoundError (node_modules/.pnpm/jest-resolve@27.4.2/node_modules/jest-resolve/build/resolver.js:579:17)
at Object.<anonymous> (src/test.ts:1:1)
Debug log
{"context":{"logLevel":20,"namespace":"Importer","package":"ts-jest","version":"27.0.7"},"message":"creating Importer singleton","sequence":1,"time":"2021-12-01T03:17:34.745Z"}
{"context":{"actualVersion":"27.4.2","expectedVersion":">=27.0.0 <28","logLevel":20,"namespace":"versions","package":"ts-jest","version":"27.0.7"},"message":"checking version of jest: OK","sequence":2,"time":"2021-12-01T03:17:34.751Z"}
{"context":{"logLevel":20,"namespace":"ts-jest-transformer","package":"ts-jest","version":"27.0.7"},"message":"created new transformer","sequence":3,"time":"2021-12-01T03:17:34.751Z"}
��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������{"context":{"logLevel":20,"namespace":"ts-jest-transformer","package":"ts-jest","version":"27.0.7"},"message":"created new transformer","sequence":6,"time":"2021-12-01T03:17:35.714Z"}
Additional context
No response
Environment
System:
OS: macOS 12.0.1
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
Yarn: 1.22.17 - /opt/homebrew/bin/yarn
npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
npmPackages:
jest: ^27.3.1 => 27.4.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Build test with Jest fails with `Could not locate module @/ ...
I'm building an app with vuejs and testing with jest and running the tests locally works, but on circleci fails with the error...
Read more >Jest Path Mapping Error: Could not locate module xyz ...
to my jest config will make it work. I needed to remove every import with leading @app/ . Pretty strange, all other aliases...
Read more >TSConfig Reference - Docs on every TSConfig option
All relative paths found in the configuration file will be resolved relative to the ... This does not affect errors on the basis...
Read more >Error Handling - The Rust Programming Language
Typically, one writes io::Result<T> , which makes it clear that you're using the io module's type alias instead of the plain definition from...
Read more >3. Using GHCi — Glasgow Haskell Compiler 9.4.3 User's ...
This means that for most modules, the module name must match the filename. If it doesn't, GHCi won't be able to find it....
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
Hi, I found your problem. The problem was actually informed by Jest that it cannot map the correct path.
As you can see the error message is
the path
/Users/carl/workspace/tests/ts-jest/examples/react/foo/$1
isn’t correct, it misses thesrc
Therefore, you need to change your config to
When compiling, TypeScript strips away the interfaces or type aliases. However, enum is not the case as TypeScript will try to resolve that enum first before attempting to compile to
js
, therefore you get the error.This is not an issue of
ts-jest
so i will close the issue.It is not the case. I use the example from the repo and forget to delete the original code.