Open VinishaDsouza opened 7 years ago
@VinishaDsouza have you found a fix for this issue? For some reason Karma is not able to resolve local modules for me. Even tho Webpack works fine and I'm reusing resolve.alias
.
Edit my answer to share my solution.
In my case, I have a tsconfig.json where specify 'baseUrl' and 'paths' for aliases definition:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"paths": {
"@app/*": ["app/*"],
"@assets/*": ["assets/*"],
"@classes/*": ["app/classes/*"],
"@components/*": ["app/components/*"],
"@directives/*": ["app/directives/*"],
"@enums/*": ["app/enums/*"],
"@env/*": ["environments/*"],
"@services/*": ["app/services/*"],
"@views/*": ["app/views/*"]
},
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
},
"exclude": [
"node_modules"
]
}
In order karma can use aliases, I just edit my tsconfig.spec.json to look like this:
{
"compilerOptions": {
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es5",
"baseUrl": ".",
"paths": {
"@app/*": ["app/*"],
"@assets/*": ["assets/*"],
"@classes/*": ["app/classes/*"],
"@components/*": ["app/components/*"],
"@directives/*": ["app/directives/*"],
"@enums/*": ["app/enums/*"],
"@env/*": ["environments/*"],
"@services/*": ["app/services/*"],
"@views/*": ["app/views/*"]
},
"types": [
"jasmine",
"node"
]
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}
Best regards!
I noticed that you'll only need to add this line "baseUrl": ".",
in your tsconfig.spec.json
file (like below), if you already had 'path' aliases definition in your tsconfig.json
file:
{
"compilerOptions": {
...
"baseUrl": ".",
...
}
Hi everyone! I am new to using karma and was wondering if anyone knows how to defina aliases in karma.
Actual behaviour
When I run karma start, I get an error saying:
Uncaught Error: Cannot find module "@angular/core" at build/StartPage-bundle.js:15165
Environment Details
karma-requirejs@^1.1.0
// Karma configuration // Generated on Fri May 29 2015 21:48:48 GMT+0200 (CEST)
var webpackConfig = require('./webpack.config.js'); module.exports = function (config) { config.set({
} ``