我希望能够在使用笑话时使用webpack别名来解析导入,并且最好参考webpack.aliases
以避免重复。
开玩笑的conf:
"jest": {
"modulePaths": ["src"],
"moduleDirectories": ["node_modules"],
"moduleNameMapper": {
"^@shared$": "<rootDir>/shared/",
"^@components$": "<rootDir>/shared/components/"
}
},
Webpack别名:
exports.aliases = {
'@shared': path.resolve(paths.APP_DIR, 'shared'),
'@components': path.resolve(paths.APP_DIR, 'shared/components'),
};
进口:
import Ordinal from '@shared/utils/Ordinal.jsx';
import Avatar from '@components/common/Avatar.jsx';
由于某种原因,@
导致了问题,因此将其删除(使用别名和导入)时,可以找到shared
但components
仍然无法解决。
FAIL src/shared/components/test/Test.spec.jsx
● Test suite failed to run
Cannot find module '@shared/utils/Ordinal.jsx' from 'Test.jsx'
我尝试使用jest-webpack-alias,babel-plugin-module-resolver和Jest / Webpack docs
FWIW,尝试切换别名顺序,保持更具体的向上和不具体的向下,例如