wallabyjs / ngCliWebpackSample

68 stars 48 forks source link

Can't make it work: "Cannot find module" errors with absolute imports #13

Closed victornoel closed 7 years ago

victornoel commented 7 years ago

Hi,

In my typescript files, I often use absolute path for my imports:

import { Workspaces } from 'app/features/cockpit/workspaces/state/workspaces/workspaces.reducer';

In that case, wallabyjs can't find these modules because it thinks the file should be: src/app/features/cockpit/workspaces/state/workspaces/workspaces.reducer.ts instead.

Is there any configuration that could be added to make this work in this case? It is a very common usage, and the auto-import functionality of vscode uses that by default.

ArtemGovorov commented 7 years ago

You may use the webpack's resolve.modules to do what you want to.

I have pushed this sample branch with an example: https://github.com/wallabyjs/ngCliWebpackSample/blob/absolutePaths/wallaby.js#L29. Specifying src/app as a module root allows to import AppComponent here https://github.com/wallabyjs/ngCliWebpackSample/blob/absolutePaths/src/app/app.component.spec.ts#L3 by an absolute path. In your case:

resolve: {
      modules: [
        path.join(wallaby.projectCacheDir, 'src')
      ]
    }

should be enough to do import { Workspaces } from 'app/...'.

victornoel commented 7 years ago

great, why not put it in the master branch then? It would make sense to have that by default… no?

ArtemGovorov commented 7 years ago

@victornoel Fair enough, good point, done.