Mapped Module Name configuration not proper
See original GitHub issueIssue :
After checking the documentation and trying to make the tsconfig path mapping work, I still get an error from mappedModuleName.replace. ● Test suite failed to run
TypeError: mappedModuleName.replace is not a function
at Resolver.resolveStubModuleName (…/node_modules/jest-resolve/build/index.js:415:34) at Object.<anonymous>
Expected behavior :
The mapping of paths in tsconfig to be able to run.
# content of ts-jest.log :
Package.json
{
"name": "entry",
"version": "0.0.1",
"description": "",
"author": "",
"license": "MIT",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "concurrently --handle-input \"wait-on dist/main.js && nodemon\" \"tsc -w -p tsconfig.build.json\" ",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && npm run build",
"start:prod": "node dist/main.js",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:async": "jest --detectOpenHandles",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@google-cloud/kms": "^1.3.0",
"@nest-middlewares/compression": "^6.0.0",
"@nest-middlewares/cookie-parser": "^6.0.0",
"@nest-middlewares/cors": "^6.0.0",
"@nest-middlewares/helmet": "^6.0.0",
"@nestjs/common": "^6.0.0",
"@nestjs/core": "^6.0.0",
"@nestjs/jwt": "^6.1.1",
"@nestjs/mongoose": "^6.1.2",
"@nestjs/passport": "^6.1.0",
"@nestjs/platform-express": "^6.0.0",
"dotenv": "^8.0.0",
"express-rate-limit": "^5.0.0",
"module-alias": "^2.2.1",
"mongoose": "^5.6.3",
"reflect-metadata": "^0.1.12",
"rimraf": "^2.6.2",
"rxjs": "^6.3.3"
},
"devDependencies": {
"@nestjs/testing": "^6.0.0",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.0",
"@types/express-rate-limit": "^3.3.1",
"@types/jest": "^23.3.13",
"@types/joi": "^14.3.3",
"@types/node": "^10.14.14",
"@types/passport-jwt": "^3.0.1",
"@types/supertest": "^2.0.7",
"concurrently": "^4.1.0",
"jest": "^24.8.0",
"nodemon": "^1.18.9",
"prettier": "^1.15.3",
"supertest": "^3.4.1",
"ts-jest": "24.0.2",
"ts-node": "8.1.0",
"tsconfig-paths": "3.8.0",
"tsconfig-paths-jest": "0.0.1",
"tslint": "5.16.0",
"typescript": "3.4.3",
"wait-on": "^3.2.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": "(/tests/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node",
"moduleNameMapper": {
"^@common/(.*)$": ["<rootDir>/common/$1"],
"^@authentication/(.*)$": ["<rootDir>/authentication/$1"]
}
}
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "src",
"paths": {
"@common/*": ["common/*"],
"@authentication/*": ["authentication/*"],
},
"incremental": true
},
"exclude": ["node_modules"]
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6
Top Results From Across the Web
(moduleNameMapper not applied) Vue jest configuration error
I have a Vue2 Rails application and tried to install Jest which worked. The problem is that I cannot test my components because...
Read more >Learning the Basics - Gradle User Manual
Configurations have a name and can extend each other. To learn more about this API have a look at ConfigurationContainer. Different kinds of...
Read more >Common Configuration - electron-builder
If not specified inside of the build configuration, productName property defined at the top level of package.json is used. If not specified at...
Read more >Configuration schema/metadata - Drupal
The core Configuration translation module builds an actual user interface on top of the schemas and lets people translate configuration. You can ...
Read more >Creating and Configuring a Model - EF Core - Microsoft Learn
If your model doesn't use mapping attributes (aka data annotations) for configuration, then all conventions with the name ending in ...
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
Strange for me it’s working. Here is the doc: https://kulshekhar.github.io/ts-jest/user/config/
@ahnpnl it finally worked, thanks for sharing the link 👍