简体   繁体   中英

ESLint importing react

I'm using eslint and getting this error because of import/no-extraneous-dependencies on a bunch of stuff inc react, chai, react-dom etc

'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it

In my package.json I have the following ('...' represents other packages that don't seem relevant):

"dependencies": {
    ...
    "react": "^15.2.1",
    ...
 },

I have a package.json in the root of my project but I also have individual package.json files for each of my components. Is there a way for it to reference the root file dependency or do I have to add it to all the individual component package.json files as well?

AFAIK, there isn't an option to reference a parent package.json (see also this issue ), because npm assumes self-contained, independent packages.

So if you want to get it working properly, you'll have to list all dependencies for each component in their respective package.json file, basically making each component an independent package.

That, or work around the reason why you need separate package.json files for each component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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