mkg0 / jest-webpack-resolver

path resolver for jest through the webpack.config. Auto detect webpack's resolve properties like aliases, plugins and more
44 stars 6 forks source link

Unknown option "jestWebpackResolver" #17

Open lucasriondel opened 5 years ago

lucasriondel commented 5 years ago

First of all, thanks for your package. It works like a charm.

But I have a small issue... I have to set a path to my webpack config, or else I have the following message:

Webpack Resolver couldn't find any configuration. Tries to resolve ./webpack.config.js
Webpack Resolver Error: Not able to find any valid webpack configuration
● Validation Error:

  Module <rootDir>/node_modules/babel-jest in the transform option was not found.
         <rootDir> is: C:\Users\LucasRIONDEL\dev\fmu\frontend

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

So I did like you said in the Readme, and i added the following to my jest.config.json:

  "jestWebpackResolver": {
    "webpackConfig": "./webpack/webpack.common.js"
  }

Which works. But when i launch jest, i have the following message:

● Validation Warning:

  Unknown option "jestWebpackResolver" with value {"webpackConfig": "./webpack/webpack.common.js"} was found.
  This is probably a typing mistake. Fixing it will remove this message.

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

Webpack Resolver using: ./webpack/webpack.common.js

Which is really weird. Do you have any idea why ?

(using jest ^23.6.0)

samparnell commented 5 years ago

Seeing the same issue with:

"jest": "^24.7.1",
"jest-webpack-resolver": "^0.3.0",
alexweber commented 4 years ago

Seems the easiest workaround here is to just rename/move your webpack config to the default or just create a symlink or something :)

That works but in turn has an annoying side effect where Webpack Resolver couldn't find any configuration. Tries to resolve ./webpack.config.js gets logged every time...

Shripad03 commented 3 years ago

what do you mean when you say move to default. can you tell more ?

patrick-s-young commented 3 years ago

I was able to resolve the Validation Warning: Unknown option "jestWebpackResolver" by moving this value from jest.config.js :

"jestWebpackResolver": {
  "silent": true,
  "webpackConfig": "webpack.config.js"   
}

to package.json.

Leaving these values in my jest.config.js:

module.exports = {
  moduleNameMapper: {
    "\\.css$": "<rootDir>/__mocks__/styleMock.js"
  },
  resolver: "jest-webpack-resolver",
  setupFilesAfterEnv: ['<rootDir>/src/setUpTests.js']
}

using:

"jest": "^26.4.2",
"jest-webpack-resolver": "^0.3.0",
alexweber commented 3 years ago

@Shripad03 I meant just webpack.config.js as a workaround but the solution provided by @patrick-s-young works perfectly!

patrick-s-young commented 3 years ago

@alexweber the Jest issue came up during a React boilerplate project. I wanted to support directory aliasing across Webpack / TypeScript / ESLint / and Jest: https://github.com/patrick-s-young/react-ts-eslint-webpack-babel

If you have any feedback for improving it, please let me know.