代码之家  ›  专栏  ›  技术社区  ›  JoeTidee

Jest-找不到“react hot loader”模块

  •  0
  • JoeTidee  · 技术社区  · 6 年前

    我用Jest编写了一个集成测试:

    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 那么,这到底是怎么回事?

    0 回复  |  直到 6 年前
        1
  •  0
  •   Anton Korzunov    6 年前

    React Hot Loader有一个babel插件,它可以添加 require('react-hot-loader') 每一个文件。所以-即使你看不到它-它可能就在那里。

    解决方案-禁用jest的react hot loader插件(或仅对web启用)。

    babel-loader 您的网页包.conf,并从中删除 .babelrc .

    推荐文章