nx: Linter fails after adding storybook config files
Current Behavior
Linting a library which has storybook configurations causes lint errors.
Expected Behavior
Linter should success without errors.
Steps to Reproduce
- Create a workspace
npx create-nx-workspace workspace
? What to create in the new workspace react
? Application name web
? Default stylesheet format emotion
? Use Nx Cloud? (It's free and doesn't require registration.) No
Creating a sandbox with Nx...
- Add a library
npm run nx g lib components
- Add Storybook configurations
npm i -D @nrwl/storybook
npm run nx g storybook-configuration components
? Configure a cypress e2e app to run against the storybook instance? Yes
? Automatically generate story files for components declared in this library? Yes
? Automatically generate *.spec.ts files in the cypress e2e app generated by the cypress-configure schematic? Yes
- Run lint
npm run lint components
Failure Logs
> nx workspace-lint && nx lint "components"
> nx run components:lint
Linting "components"...
/Users/puku0x/Desktop/workspace/libs/components/.storybook/main.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: libs/components/.storybook/main.js.
The file must be included in at least one of the projects provided
/Users/puku0x/Desktop/workspace/libs/components/.storybook/preview.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: libs/components/.storybook/preview.js.
The file must be included in at least one of the projects provided
/Users/puku0x/Desktop/workspace/libs/components/.storybook/webpack.config.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: libs/components/.storybook/webpack.config.js.
The file must be included in at least one of the projects provided
✖ 3 problems (3 errors, 0 warnings)
Lint errors found in the listed files.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! workspace@0.0.0 lint: `nx workspace-lint && nx lint "components"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the workspace@0.0.0 lint script.
Environment
> NX Report complete - copy this into the issue template
nx : Not Found
@nrwl/angular : Not Found
@nrwl/cli : 10.3.0
@nrwl/cypress : 10.3.0
@nrwl/eslint-plugin-nx : 10.3.0
@nrwl/express : Not Found
@nrwl/jest : 10.3.0
@nrwl/linter : 10.3.0
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/react : 10.3.0
@nrwl/schematics : Not Found
@nrwl/tao : 10.3.0
@nrwl/web : 10.3.0
@nrwl/workspace : 10.3.0
typescript : 4.0.3
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 22 (9 by maintainers)
Commits related to this issue
- fix(storybook): fix(storybook): react eslint ignores for storybook ISSUES CLOSED: #3867 — committed to juristr/nx by juristr 4 years ago
- fix(storybook): react eslint ignores for storybook ISSUES CLOSED: #3867 — committed to juristr/nx by juristr 4 years ago
- fix(storybook): react eslint ignores for storybook ISSUES CLOSED: #3867 — committed to juristr/nx by juristr 4 years ago
- fix(storybook): linting react storybook files with eslint ISSUES CLOSED: #3867 — committed to nrwl/nx by juristr 3 years ago
- fix(storybook): linting react storybook files with eslint ISSUES CLOSED: #3867 — committed to nrwl/nx by juristr 3 years ago
- fix(storybook): linting react storybook files with eslint (#5146) ISSUES CLOSED: #3867 — committed to nrwl/nx by juristr 3 years ago
It can be solved by modifying
ignorePatternsin.eslintrc.json.When dealing with an Angular library that has Storybook files, the issue may also pop up:
To fix the issue, simply add your Storybook’s
tsconfig.jsontoparserOptions.projectin your library’s.eslintrc.jsonfile.Before:
After:
Happy linting!
Hi Folks,
The lint errors around globals like
moduleand__dirnamenot being available has been fixed in11.3.0which was released yesterdayThe lint errors around
@typescript-eslint/no-var-requireshas been fixed in11.3.0which was released yesterdayFor Webstorm users, we spent some time researching this and it turns out it behaves differently to the command line and VSCode in this regard. We also found that Webstorm’s choice of behaviour here has caused issues with all monorepo tools (like lerna, Nx etc) grouped under here: https://youtrack.jetbrains.com/issue/WEB-47135#focus=Comments-27-4419848.0-0 and so they have implemented a configuration option to address this:
Rather than updating their eslint configs from what Nx generates, Webstorm users should:
Working directoriesoption to be./- leave all the other options unchanged. For example on my machine:Now everything should work as it does in VSCode and on the command line.
I believe with those two points (latest Nx release and Webstorm instructions) all the issues outlined on this thread have been covered so closing for now.
Thanks!
Ah, thank you. It’s so annoying that globs don’t work for dot-prefixed files and folders. And I always forget that.
Ok. I found something that fixed this issue for me… but might cause other issues (maybe).
In your library, there is that root tsconfig.json that has references something like this:
When comparing the
./tsconfig.lib.json,./tsconfig.spec.json, and./.storybook/tsconfig.jsonthe major difference was that the storybook config didn’t havecompilerOptionsin there. I made a copy of thetsconfig.lib.jsonfile and named ittsconfig.stories.jsonand then just changed it to be:Not sure why this worked, but it did. Maybe some lame pathing bug with eslint? Or maybe an eslint pathing issue with just Webstorm? I don’t think I get this error in VSCode. Or maybe VSCode just doesn’t share it so blatently.
Thanks for that comment, @JamesHenry! We’d been seeing this error since switching to v11, and that change to settings fixed it.
I didn’t see other people reporting an error with the ‘You have used a rule which requires parserService to be generated. You must therefore provide a value for the “parserOptions.project” property for @typescript-eslint/parser"’ message, but fortunately your suggestion fixed it.
Perhaps someone else will see this comment and find out that your suggestion saves aggravation 😃
Hi @puku0x @iamandrewluca all the issues (
parserOptions.projectand"@typescript-eslint/no-var-requires"should be fixed in the latest release11.3.0. Could you give it a try and get back to me? I just tried it and it works!! 😃 😃@johngrimsey @Brian-McBride see the comment above by @JamesHenry !! A similar issue came up here as well.
Thank you all very much for taking the time to find the issues and find fixes for these, too! You’re the best!!
The
parserOptions.projecterror has been fixed in Nx v11.However, we need to override
@typescript-eslint/no-var-requires.Another solution is to disable ESLint for the lines using
requirestatement.After reading #5146 , I can finally manage Nx + Storybook + ESLint! Thank you @juristr !!
I had es-linting issues in IntelliJ after adding the Storybook plugin and adding it to a lib.
I fixed the offending scaffolded lib’s
.eslintrc.jsonby removing what appears to be a repeated path to tsconfig files. Because the offending estlintrc.json file is also in the lib, no path is needed (it doesn’t exist):before:
after:
I’m not sure if I’ve caused any wider issues here. Running
nx linton the module seemed to be working ok. I’ve only just put the fix in so will update if something’s wrong.@puku0x I think is not fixed yet. See last comment https://github.com/nrwl/nx/pull/3923 I still get
parserOptions.projecterror with11.1.1