jest.config.js 失败 - 意外的标记“.”在 module.exports

jest.config.js fails - unexpected token '.' in module.exports

我一定是遗漏了什么,但我很难理解这个错误。

.怎么会出乎意料module.exports={}

请指出正确的方向。谢谢!

\jest.config.js:16
    module.exports = {
          ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at readConfigFileAndSetRootDir (...\node_modules\jest-config\build\readConfigFileAndSetRootDir.js:119:22)
    at readConfig (...\node_modules\jest-config\build\index.js:217:65)
    at readConfigs (...\node_modules\jest-config\build\index.js:406:32)
npm ERR! Test failed.  See above for more details.

jest.config.js:

module.exports = {
    transform: {
        "^.+\.[jt]sx?$": "<rootDir>/jest-preprocess.js",
    },
    moduleNameMapper: {
        ".+\.(css|styl|less|sass|scss)$": `identity-obj-proxy`,
        ".+\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": `<rootDir>/__mocks__/file-mock.js`,
    },
    testPathIgnorePatterns: [`node_modules`, `\.cache`, `<rootDir>.*/public`],
    transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
    globals: {
        __PATH_PREFIX__: ``,
    },
    testURL: `http://localhost`,
    setupFiles: [`<rootDir>/loadershim.js`],
    module.exports = {
        setupFilesAfterEnv: ["<rootDir>/setup-test-env.js"],
    }
};

您在底部的对象中嵌入了一个额外的 module.exports。看起来文件应该是:

module.exports = {
    transform: {
        "^.+\.[jt]sx?$": "<rootDir>/jest-preprocess.js",
    },
    moduleNameMapper: {
        ".+\.(css|styl|less|sass|scss)$": `identity-obj-proxy`,
        ".+\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": `<rootDir>/__mocks__/file-mock.js`,
    },
    testPathIgnorePatterns: [`node_modules`, `\.cache`, `<rootDir>.*/public`],
    transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],
    globals: {
        __PATH_PREFIX__: ``,
    },
    testURL: `http://localhost`,
    setupFiles: [`<rootDir>/loadershim.js`],
    setupFilesAfterEnv: ["<rootDir>/setup-test-env.js"],  
};