Jest: Cannot find relative to Webpack root dir module

Created on 2 Oct 2015  路  2Comments  路  Source: facebook/jest

I use Webpack.

It has "resolve" config like this:

resolve: {
  root: path.resolve('./src'),
  extensions: ['', '.js', '.jsx', '.json'],
  modulesDirectories: ['node_modules']
}

when I'm trying to require a relative module to the root path (with webpack it requires src/apps/foo/bar.js)

require('apps/foo/bar');

jest are falling with exception:

Cannot find module 'apps/foo/bar' from...

Do I must use "require" with the file-to-file relations only?

UPDATE:

I created a repo with simple example of my issue: https://github.com/Poplava/jest-app

All 2 comments

That won't work with jest -- it will assume that "app" or "modules" are in node_modules.
Why don't you use relative requires? In your example just do require('../../modules/sum').

Thanks a lot!

It is ugly for me to import module like common/foo/bar from the deep component with ../../../../.. :)

I thought it will be good to have option "resolve" (like in the WebPack) or something like that.

Was this page helpful?
0 / 5 - 0 ratings