Mocha cannot find module 'can-connect/can/super-map/'

My npm test command, mocha components/*/*.cmd.test.js -r babel-register -r jsdom-global/register fails as mocha cannot find superMap which is imported like so, import superMap from "can-connect/can/super-map/";. However mocha could find jquery which is imported like so, import $ from "jquery";. What am I missing?

Does this work?

import superMap from "can-connect/can/super-map/super-map";

Excluding the file name when it repeats the last folder name is a StealJS feature, so that might be the issue if your code isn’t being loaded by StealJS.

1 Like

Works! I assumed JavaScript can import from a folder name. After you said revised how it works. Thank you.

1 Like

Could you explain why importing jquery works like that?

You can load jquery because they have set the main in their package.json: https://github.com/jquery/jquery/blob/master/package.json#L6.

So when that package is required it loads the file pointed to by main.

1 Like