Getting SourceMap position not found for trace. I am trying to build a unit test framework using typescript, mocha, karma, and karma-typescript and getting the following issue. I tried using karma-sourcemap-loader but still, there is no luck. Can anyone please guide me on what am I missing here?
karma-typescript should be able to handle these source map things by themself in between multiple transformations.
Fetching /Users/test/sourcecode/test-web-ui/node_modules/karma-typescript/dist/client/commonjs.js
17 08 2021 23:47:06.959:DEBUG [web-server]: serving (cached): /Users/raukumar/sourcecode/test-web-ui/node_modules/karma-typescript/dist/client/commonjs.js
17 08 2021 23:47:07.357:WARN [reporter]: SourceMap position not found for trace: Uncaught Error: Can't find @react/react-spectrum/Button [undefined] (required by /Users/test/sourcecode/elements-web-ui/src/editors/doc/stage/actions/StageActionsView.tsx)
at http://localhost:9882/base/node_modules/karma-typescript/dist/client/commonjs.js?f5014f1e344ba3e2f0d92afe67b92f3001c46c90:13:17
I tried this solution SourceMap position not found for trace: AssertionError (Karma-Typescript) but after this, I am getting some different issues.
Uncaught Error: Can't find @react/react-spectrum/Button [undefined] (required by /Users/test/sourcecode/src/somefile.tsx
Karma.conf
module.exports = (config) => {
config.set({
// basePath: '',
//configFile: join(__dirname, "testing.tsconfig.json"),
plugins: ['karma-chrome-launcher', 'karma-mocha', 'karma-typescript', 'karma-webpack','karma-mocha-reporter','karma-sourcemap-loader'],
frameworks: ['mocha', 'karma-typescript'],
preprocessors: {
"**/*.ts": ["karma-typescript","sourcemap"],
"**/*.tsx": ["karma-typescript","sourcemap"], // *.tsx for React Jsx
'**/*.js': ["sourcemap"]
//"src/**/*.js": ["babel"]
},
logLevel: config.LOG_DEBUG,
browsers: ['Chrome'],
singleRun: true,
autoWatch: false,
color:true,
reporters: ["mocha", "karma-typescript"],
//files: [{ pattern: "src/**/*.ts" }, {pattern: "src/**/*.tsx" }, {pattern: "src/**/*.js"}],
files: [{ pattern: "src/**/!(*.spec).?(ts|tsx)" }, { pattern: "src/**/!(*.integration.spec).?(ts|tsx)" } ],
//webpack: webpackConfig,
karmaTypescriptConfig: {
// Allow tests to run even when there are compiler errors
stopOnFailure: true,
bundlerOptions: {
acornOptions: {
ecmaVersion: 8,
},
transforms: [
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("karma-typescript-es6-transform")({
// eslint-disable-next-line @typescript-eslint/no-var-requires
//presets: [require("@babel/preset-env",{ "useBuiltIns": "entry"})],
//plugins: ['@babel/plugin-transform-spread'],
presets: [
["env", {
targets: {
browsers: ["last 2 Chrome versions"]
}
}]
]
})
]
},
compilerOptions: {
target: "ES2017",
lib: ['DOM', 'ES2015', 'ES2017'],
module: "CommonJS",
// Remove incompatible options
//incremental: false
},
tsconfig: "testing.tsconfig.json"
}
});
}
tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"module": "CommonJS",
"incremental": true,
"noUnusedParameters": false,
"sourceMap": true,
"jsx": "react",
"strict": true,
"esModuleInterop": true,
"declaration": true,
"declarationMap": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*.ts","src/**/*.tsx"],
"exclude": ["node_modules"]
}