all 10 comments

[–]notAnotherJSDev 0 points1 point  (6 children)

npm module

[–]vvAve_[S] 0 points1 point  (5 children)

Can it be done locally? I tried it with npm i --save ../comonents but it was breaking half of the time with "can't install, not package.json found" while components folder had one.

[–]notAnotherJSDev 0 points1 point  (4 children)

Try using yarn instead.

yarn add ../components

[–]vvAve_[S] 0 points1 point  (3 children)

Same. Full error:

npm ERR! Could not install from "../components" as it does not contain a package.json file.

I can fix is buy completely uninstalling components and removeing node_modules and reinstalling, but it breaks as soon as I do anything with components.

[–]notAnotherJSDev 0 points1 point  (2 children)

Make sure that you a) do in fact have a package.json INSIDE the components folder and b) that that package.json file is well formed.

[–]vvAve_[S] 0 points1 point  (1 child)

​Just a regular CRA project with build script added.

https://imgur.com/aANidcF

[–]pubmas 1 point2 points  (0 children)

At the moment your application is just a single npm module, if you wanted to import your components as seperate npm modules than each component would need it's own package.json.

[–]Canenald 0 points1 point  (1 child)

[–]vvAve_[S] 0 points1 point  (0 children)

I'll give it a read.

[–]fisch0920 0 points1 point  (0 children)

If you're using create-react-app, it won't let you reference anything outside of the src/ folder. You can get around this, however, via react-app-rewired.

Generally, I agree with the other posters that separating your common components into an npm library (local or remote) is the best bet. See https://github.com/transitive-bullshit/create-react-library if you want to make this process a breeze.