开玩笑 - 找不到模块'react-hot-loader'



我已经使用开玩笑编写了集成测试:

import 'jest-styled-components';
import React from 'react';
import { remAuto } from 'tidee-life-theme';
test('blah', () => {});

正在得到这个奇怪的输出:

 Cannot find module 'react-hot-loader' from 'core.js'
       7 | const core = {
       8 |     'background-color': '#fff',
    >  9 |     'color': fontColor,
         |                                                      ^
      10 |     'font-family': fontFamily,
      11 |     'font-family-bold': fontFamilyBold,
      12 |     'font-size': fontSize,
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at ../tidee-life-theme/src/core.js:9:91
      at Object.<anonymous> (../tidee-life-theme/src/core.js:11:3)

当我查看core.js时,没有提及react-hot-loader

export const fontColor = "#666";
export const fontFamily = `'open_sansregular', helvetica, arial`;
export const fontFamilyBold = `'open_sansbold', helvetica, arial`;
export const fontSize = 13;
export const fontLineHeight = 17 /13;
const core = {
    'background-color': '#fff',
    'color': fontColor,
    'font-family': fontFamily,
    'font-family-bold': fontFamilyBold,
    'font-size': fontSize,
    'line-height': fontLineHeight,
};
export default core;

我正在使用Lerna,并且tidee-life-theme位于与测试正在进行的包装相邻的软件包中。那么,这里到底发生了什么?

react-hot-loader具有一个babel插件,该插件会将require('react-hot-loader')添加到每个文件中。因此 - 即使您看不到它 - 它可能存在。

解决方案 - 禁用开玩笑的React-Hot-Loader插件(或仅适用于Web)。

有不同的方法可以做到。最简单的一个 - 通过webpack.conf中的babel-loader配置选项添加它,然后从.babelrc中删除。

最新更新