小编dco*_*s83的帖子

SyntaxError:使用 Jest 时出现意外的令牌“导出”(来自“react-leaflet”)

我突然得到这个错误。

代码在我使用时工作正常,但在使用Jest测试时会弹出此问题。...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ...................................................... ......

细节:

    C:\node_modules\react-leaflet\lib\index.js
:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { us
eMap, useMapEvent, useMapEvents } from './hooks.js';
                                                                                      ^^^^^^     

    SyntaxError: Unexpected token 'export'

       9 | } from 'react-leaflet';
      10 | import { private } from 'private';
    > 11 |
         | ^
Run Code Online (Sandbox Code Playgroud)

这是我的笑话配置

module.exports = {
  moduleNameMapper: {
    // Resolve .css and similar files to identity-obj-proxy instead.
    '.+\\.(css|styl|less|sass|scss)$': 'identity-obj-proxy',
    // Resolve .jpg and similar files to __mocks__/file-mock.js
    '.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
      '<rootDir>/__mocks__/file-mock.js',
  },

  clearMocks: true,

  coverageDirectory: 'coverage',
  // …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs jestjs babeljs react-leaflet

5
推荐指数
1
解决办法
2644
查看次数

标签 统计

babeljs ×1

javascript ×1

jestjs ×1

react-leaflet ×1

reactjs ×1