admin管理员组文章数量:1333201
In my react app, I am importing a module as follows:
import { isValidAddress } from 'orbit-db';
Some dependency of isValidAddress
requires multicodec/src/base-table
(see this line).
However, jest gives the following error:
Configuration error:
Could not locate module multicodec/src/base-table mapped as:
/Users/h/Documents/code/orbit-db-time-machine/src/base-table.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/src\/(.*)$/": "/Users/h/Documents/code/orbit-db-time-machine/src/$1"
},
"resolver": null
}
I think that this is happening because the jest dependency rule "/src\/(.*)$/"
is re-writing all paths with src
in them to <rootDir>/src
, even if they e from a npm module.
I tried to fix this by adding the following config to my package.json
:
"jest": {
"moduleNameMapper": {
"/multicodec\/(.*)$/": "<rootDir>/node_modules/multicodec/$1"
}
}
However, this did not change the error. The only way I have been able to remove the error is by removing my import
statement - however, this is required in my code.
Note: The code works when run from my react app, it only breaks when I run jest.
In my react app, I am importing a module as follows:
import { isValidAddress } from 'orbit-db';
Some dependency of isValidAddress
requires multicodec/src/base-table
(see this line).
However, jest gives the following error:
Configuration error:
Could not locate module multicodec/src/base-table mapped as:
/Users/h/Documents/code/orbit-db-time-machine/src/base-table.
Please check your configuration for these entries:
{
"moduleNameMapper": {
"/src\/(.*)$/": "/Users/h/Documents/code/orbit-db-time-machine/src/$1"
},
"resolver": null
}
I think that this is happening because the jest dependency rule "/src\/(.*)$/"
is re-writing all paths with src
in them to <rootDir>/src
, even if they e from a npm module.
I tried to fix this by adding the following config to my package.json
:
"jest": {
"moduleNameMapper": {
"/multicodec\/(.*)$/": "<rootDir>/node_modules/multicodec/$1"
}
}
However, this did not change the error. The only way I have been able to remove the error is by removing my import
statement - however, this is required in my code.
Note: The code works when run from my react app, it only breaks when I run jest.
Share Improve this question edited Oct 13, 2019 at 7:04 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Oct 12, 2019 at 23:52 Hannes HertachHannes Hertach 5295 silver badges27 bronze badges2 Answers
Reset to default 2This was a bug and has been fixed: https://github./facebook/create-react-app/issues/7818
I remember ing across a similar problem when using the KY library in my React project with Jest. You might have to also use transformIgnorePatters to overe this.
There was an issues thread where they discussed this in the KY repo that you might also find helpful, although some of the solutions are very specific to that project: https://github./sindresorhus/ky/issues/170
版权声明:本文标题:javascript - Jest "Could not locate module" if any dependency has "src" in path - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281244a2446130.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论