简体   繁体   English

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

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

I must be missing something but I'm struggling to understand this error.我一定是遗漏了什么,但我很难理解这个错误。

How can .怎么可能. be unexpected in module.exports={} ?module.exports={}中出乎意料?

Please point me in the right direction.请指出正确的方向。 Thanks!谢谢!

\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 : 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"],
    }
};

You have an extra module.exports embedded in the object at the bottom.您在底部的module.exports looks like the file should be:看起来文件应该是:

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"],  
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM