karma-jspm icon indicating copy to clipboard operation
karma-jspm copied to clipboard

404 when using import

Open cAhmad opened this issue 8 years ago • 8 comments

Hi, I'm trying to use karma-jspm, after your last release I do not have the too many open file so I can go on.

Now I'm facing a new issue, I read the #91, but that's not my case, my jspm.config.js has an empty baseURL

When I run my es5 tests it fails with:

ReferenceError: module is not defined

Which is fine since I didn't import it (my app is with AngularJS)

So when I try to:

import angular from 'angular';
import 'angular-mocks';

I get this error:

18 05 2016 11:46:32.089:WARN [web-server]: 404: /base/jspm_packages/npm/[email protected]
Chrome 50.0.2661 (Linux 0.0.0) ERROR
  Error: XHR error (404 Not Found) loading /jspm_packages/npm/[email protected]
        Error loading /jspm_packages/npm/[email protected]
        Error loading /test/javascript/unit/i18n.spec.js

Does anyone have any tips or idea, what I'm missing here?

cAhmad avatar May 18 '16 10:05 cAhmad

I'm currently having what looks to be the same issue, but with TypeScript.

Ixonal avatar Jun 07 '16 01:06 Ixonal

This looks like something you could fix with a proxy configuration in karma like this:

proxies: {
    '/jspm_packages/': '/base/jspm_packages/'
},

Provided that jspm_packages lives in the root of your project. Can you show your existing proxies configuration and the directory structure of your project, + the karma.conf.js file contents?

sergei-maertens avatar Jun 07 '16 10:06 sergei-maertens

I've been through many permutations for the config file, including using proxies, but keep getting the same issue.

here's my config file

module.exports = function(config) {
  config.set({
    //logLevel: config.LOG_DEBUG,

    frameworks: ["jspm", "jasmine"],
    reporters: ["progress"],
    browsers: ["PhantomJS"],
    // files: [
    //   { pattern: "test/*.spec.ts", included: true },
    //   { pattern: "dist/**/*.js", included: false, served: true }
    // ],

    proxies: {
      "jspm_packages/": "base/jspm_packages/",
      "test/": "base/test/",
      "src/": "base/src/"
    },

    jspm: {
      config: "./config.js",

      loadFiles: [
        "test/**/*.ts"
      ],
      serveFiles: [
        "jspm_packages/**/*.js",
        "src/**/*.ts"
      ],

      paths: {
        "aurelia-service-generator/*": "dist/*"
      }
    }//,

    // preprocessors: {
    //   "test/**/*.ts": ["typescript"]
    // },

    // typescriptPreprocessor: {
    //   options: {
    //     noResolve: true,
    //     module: 'amd'
    //   },
    //   transformPath: function(path) {
    //     return path.replace(/\.ts$/, '.js');
    //   }
    // }
  });
}

And here's my Systemjs config file

System.config({
  //defaultJSExtensions: true,

  transpiler: "typescript",
  paths: {
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*"
  },

  map: {
    "typescript": "npm:[email protected]",
    "github:jspm/[email protected]": {
      "os-browserify": "npm:[email protected]"
    },
    "npm:[email protected]": {
      "os": "github:jspm/[email protected]"
    },
    "npm:[email protected]": {
      "os": "github:jspm/[email protected]"
    }
  }
});

And just in case, here's the spec I'm trying to load

import { TypeScriptServiceBuilder } from "../src/construction/typeScript/TypeScriptServiceBuilder";

describe("TypeScriptServiceBuilder", function() {

  it("exists", function() {
    expect(TypeScriptServiceBuilder).toBeTruthy();
  });

});

Aaaannnnndddddd here's a (slightly abridged, emptied node_modules) copy of my directory structure

+---build
+---dist
|   +---construction
|   |   +---es2015
|   |   +---es5
|   |   +---interfaces
|   |   \---typeScript
|   +---dts
|   |   +---construction
|   |   |   +---es2015
|   |   |   +---es5
|   |   |   +---interfaces
|   |   |   \---typeScript
|   |   +---gulp
|   |   +---interpretation
|   |   |   \---swagger
|   |   |       \---interfaces
|   |   +---Swagger
|   |   |   \---interfaces
|   |   \---util
|   +---gulp
|   +---interpretation
|   |   \---swagger
|   |       \---interfaces
|   +---Swagger
|   |   \---interfaces
|   \---util
+---jspm_packages
|   +---github
|   |   \---jspm
|   |       \[email protected]
|   \---npm
|       [email protected]
|       \[email protected]
|           +---bin
|           \---lib
+---node_modules
+---src
|   +---construction
|   |   +---es2015
|   |   +---es5
|   |   +---interfaces
|   |   \---typeScript
|   +---gulp
|   +---interpretation
|   |   \---swagger
|   |       \---interfaces
|   \---util
+---test
|   \---resources
\---typings
    +---form-data
    +---glob
    +---glob-stream
    +---jasmine
    +---minimatch
    +---node
    +---request
    +---vinyl
    \---vinyl-fs

Ixonal avatar Jun 07 '16 22:06 Ixonal

@sergei-maertens just in case, ping.

Ixonal avatar Jun 11 '16 04:06 Ixonal

I have no quick ideas, sorry :( On Jun 11, 2016 06:05, "Benjamin McGregor" [email protected] wrote:

@sergei-maertens https://github.com/sergei-maertens just in case, ping.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Workiva/karma-jspm/issues/155#issuecomment-225335429, or mute the thread https://github.com/notifications/unsubscribe/AFQ01hT8u8utXB-Mwpz8UV8UQWPIQyn2ks5qKjPzgaJpZM4IhH7T .

sergei-maertens avatar Jun 11 '16 09:06 sergei-maertens

Perhaps you need to install plugin-babel:

jspm install npm:systemjs-plugin-babel

FredLoney avatar Jun 14 '16 00:06 FredLoney

@FredLoney I'm using TypeScript instead of Babel, and it's set up to use it in the system config and it exists in the jspm_packages folder

Ixonal avatar Jun 14 '16 00:06 Ixonal

This might be karma-jspm/jspm interaction weirdness. I use typescript as well, but my karma-jspm fails on a missing traceur library. When I add it, the test runs. jspm checks the transpiler name against a list of known transpilers and loads libraries accordingly. traceur is the first in the list and babel is the last--and default--in the list. In my situation, this is the only place in the entire app that could potentially request a traceur library. It could be that jspm is not detecting your transpiler name correctly and falls through to babel. If so, the first library jspm would request is babel-core.

FredLoney avatar Jun 21 '16 23:06 FredLoney