nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 50 forks source link

SourceMap position not found for trace: TypeError: ... #184

Closed svi3c closed 7 years ago

svi3c commented 8 years ago

Hello,

I've got the following karma configuration:

module.exports = (config) ->
  config.set
    frameworks: ["browserify", "jasmine"]
    files: [
      "node_modules/angular/angular.js"
      "node_modules/angular-mocks/angular-mocks.js"
      "app/**/*.spec.js"
    ]
    preprocessors:
      "app/**/*.js": ["browserify"]
    browserify:
      debug: true
      configure: (bundle) ->
        bundle.once "prebundle", ->
          bundle.transform "babelify"
    reporters: ["dots"]
    port: 8877
    colors: true
    logLevel: config.LOG_INFO
    autoWatch: false
    browsers: ["PhantomJS"]
    singleRun: true

When I get an error, the stack trace cannot be linked with the source maps:

SourceMap position not found for trace: TypeError: undefined is not an object (evaluating '[...]') in http://localhost:8877/absolute/tmp/c6ec59ad61f294fd51d07305eeaf5c17.browserify?ed7e1e8ce42e802c4d614ba337bf1dc8ac6e27b9 (line 182)

Any Idea what's going wrong here?

bendrucker commented 8 years ago

Can we get some code please?

svi3c commented 8 years ago

Sure! The problem is that the issue occurs in a closed source project. I'll boil it down to the essentials when I've got time.

hazboun commented 8 years ago

I believe I have the same error testing React. my karma.conf.js looks like this:

module.exports = function(config) {

  config.set({

    basePath: ".",

    frameworks: ['jasmine', 'browserify'],

    preprocessors: {

      'tests/**/*.js': ['babel', 'browserify']

    },

    babelPreprocessor:{

        options: {

          presets: ['es2015'],

          sourceMap: 'inline'

        }
    },

    browserify: {
      debug: true,

      transform: [ 'babelify'],

      configure: function(bundle){

        bundle.on("prebundle", function(){ 

          bundle.external("react/addons");

          bundle.external("react/lib/ReactContext");

          bundle.external("react/lib/ExecutionEnvironment");

        });

      }

    },

    reporters: ['spec'],

    colors: true,

    logLevel: config.LOG_INFO,

    autoWatch: true,

    browsers: ['PhantomJS'],

    files: [

      'tests/**/*.js'

    ]

  });

};

My one and only test file has:

'use strict';

import React from 'react';
import {mount} from 'enzyme';
import sinon from 'sinon';
import Footer from '../src/js/components/Footer';

describe('<Footer/>', () => {

    it('renders footer <Footer/> component', () => {
        const wrapper = mount(<Footer/>);
        console.log(wrapper);
        expect(wrapper.find('.app_footer')).to.have.length(1);
    });
});

Footer component has only one div with class name '.app_footer'. The error I get is this:

SourceMap position not found for trace: TypeError: undefined is not an object (evaluating 'expect(wrapper.find('.app_wrapper')).to.have') in http://localhost:9876/absolute/var/folders/wr/hkjbf_wd3tnf5j9t2p8ndnt40000gn/T/40f5d6b577f0f7e57a2eb4aabc9edf46.browserify?d01138ff9d27c662c126752a88873bdf74683625 (line 61603)
http://localhost:9876/absolute/var/folders/wr/hkjbf_wd3tnf5j9t2p8ndnt40000gn/T/40f5d6b577f0f7e57a2eb4aabc9edf46.browserify?d01138ff9d27c662c126752a88873bdf74683625:61603:42
nikku commented 8 years ago

@hazboun Can you provide us with a sample project that reproduces the issue?

hazboun commented 8 years ago

Sample.zip This is my sample project. Btw, I only get that error when the test fails.

leyayun commented 8 years ago

I got the same error.

bendrucker commented 8 years ago

Please use reactions to say "me too" instead of notifying everyone on a thread

SpainTrain commented 8 years ago

This may not be specific to karma-browserify - I am using karma-webpack and am experiencing the same behavior.

nikku commented 8 years ago

That is what I thought, too. Did you find an upstream bug in TypeScript or a sourcemap library?

SpainTrain commented 8 years ago

I have not tracked down the root cause in an upstream yet, but I am not using typescript, so that eliminates that possibility =-D

wethinkagile commented 7 years ago

I have Typescript too and same error.

yantakus commented 7 years ago

Any update on this?

fknop commented 7 years ago

I just had the same issue with Typescript 2.2.x. I reverted to version 2.0.8 and the issue was fixed.

ChrisGibb commented 7 years ago

This is a bit random. But I had this issue. When I deleted a line that just has a ; on it the error disappeared.

I'm using typescript.

nikku commented 7 years ago

As indicated in the comments, this seems to be a TypeScript source map generation.

ryanki1 commented 7 years ago

Can also happen if one of your typescript files has a compile error - in my case it was one of my test files as referenced by the error:

02 06 2017 15:16:54.630:WARN [reporter]: SourceMap position not found for trace: undefined PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR { "line": 104034, "sourceURL": "src/test.ts", ....

MattWilliamsDev commented 4 years ago

I'm not using typescript and get this error. just regular source-map.

petrind commented 4 years ago

I encountered this issue, and it turned out it is because I didn't use correct mode for webpack config in karma.conf.js

Solution karma.conf.js

webpack: {
      mode: 'development',

version

"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
septagram commented 4 years ago

If you are using karma-sourcemap-loader, try switching to karma-source-map-support.

My case: Babel, no TypeScript, Webpack and not Browserify, I was using karma-sourcemap-loader.

After switching, both use cases work perfectly fine, outputting mapped stack traces, no extra warnings.

This is likely not to be relevant to the OP's problem, but this issue comes up as the Google's top hit for "SourceMap position not found for trace", so I hope that'll help someone.