jest.config.js 失败 - 意外标记“.” 在 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"],

    }

};


胡说叔叔
浏览 144回答 1
1回答

胡子哥哥

您module.exports在底部的对象中嵌入了额外的内容。看起来文件应该是:module.exports = {&nbsp; &nbsp; transform: {&nbsp; &nbsp; &nbsp; &nbsp; "^.+\\.[jt]sx?$": "<rootDir>/jest-preprocess.js",&nbsp; &nbsp; },&nbsp; &nbsp; moduleNameMapper: {&nbsp; &nbsp; &nbsp; &nbsp; ".+\\.(css|styl|less|sass|scss)$": `identity-obj-proxy`,&nbsp; &nbsp; &nbsp; &nbsp; ".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": `<rootDir>/__mocks__/file-mock.js`,&nbsp; &nbsp; },&nbsp; &nbsp; testPathIgnorePatterns: [`node_modules`, `\\.cache`, `<rootDir>.*/public`],&nbsp; &nbsp; transformIgnorePatterns: [`node_modules/(?!(gatsby)/)`],&nbsp; &nbsp; globals: {&nbsp; &nbsp; &nbsp; &nbsp; __PATH_PREFIX__: ``,&nbsp; &nbsp; },&nbsp; &nbsp; testURL: `http://localhost`,&nbsp; &nbsp; setupFiles: [`<rootDir>/loadershim.js`],&nbsp; &nbsp; setupFilesAfterEnv: ["<rootDir>/setup-test-env.js"],&nbsp;&nbsp;};
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript