语法错误:不能在模块外使用导入语句 - jest

时间:2021-02-17 08:31:18

标签: javascript reactjs jestjs

我在我的自定义框架中使用 jest 测试框架,该框架基于 react 和 babel。

当我运行命令“npm run test”时。我收到以下错误。

/homes/akapil/ui_new/ui/portal/local-deps/slipstream-components/node_modules/antd/es/checkbox/index.js:1 ({"Object.":function(module,exports,require,__dirname,__filename,global,jest){import Checkbox from './Checkbox'; ^^^^^^^

语法错误:不能在模块外使用导入语句

<块引用>

1 | import Checkbox, { CheckboxChangeEvent } from 'antd/es/checkbox'; | ^ 2 |导入 'antd/es/checkbox/style'; 3 | import React, { Component } from 'react'; 4 |

在 Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14) 在对象。 (portal/local-deps/slipstream-components/src/components/SCheckbox/SCheckbox.tsx:1:1)

我的 jest.config.js

module.exports = {
    "roots": [
      "<rootDir>/plugins"
    ],
    "collectCoverageFrom": [
      "plugins/**/*.{js,jsx,ts,tsx}",
      "!plugins/**/*.d.ts"
    ],
    "setupFiles": [
      "<rootDir>/node_modules/react-app-polyfill/jsdom.js"
    ],
    "setupFilesAfterEnv": [
      "<rootDir>/setupTests.js"
    ],
    "testMatch": [
      "<rootDir>/plugins/**/__tests__/**/*.{js,jsx,ts,tsx}",
      "<rootDir>/plugins/**/*.{spec,test}.{js,jsx,ts,tsx}"
    ],
    "testEnvironment": "jsdom",
    "testRunner": "<rootDir>/node_modules/jest-circus/runner.js",
    "transform": {
      "^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": "<rootDir>/node_modules/react-app-rewired/scripts/utils/babelTransform.js",
      "^.+\\.css$": "<rootDir>/node_modules/react-scripts/config/jest/cssTransform.js",
      "^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "<rootDir>/node_modules/react-scripts/config/jest/fileTransform.js"
    },
    "transformIgnorePatterns": [
      "/node_modules/(?!(slipstream-components)/).*/"
    ],
    "modulePaths": [],
    "moduleNameMapper": {
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    },
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ],
    "watchPlugins": [
      "jest-watch-typeahead/filename",
      "jest-watch-typeahead/testname"
    ],
    "resetMocks": true,
    // "rootDir": "<rootDir>/plugins"
  }

0 个答案:

没有答案