![]() I have a suspicion that for some reason the backend app is not looking inside of node_modules for this package based on the require stack. The weird thing is, the frontend app is able to see the module fine when doing import from "shared"īut the backend app is throwing the following error (with the exact same import statement as above): Error: Cannot find module 'shared' I then do yarn workspace frontend add shared and yarn workspace server add shared and successfully find that the shared package is listed as a workspace dependency for server and frontend in yarn listįurthermore, I am able to find the shared package inside of the node_modules of each of the workspaces. I've so far set up Yarn workspaces with the following directory structure: monorepo Make sure to either run your code using NODE_OPTIONS="-require /path/to/.pnp.js" or to call it using yarn node which does the right thing transparently (whether you’re using PnP or not).I'm attempting to set up a monorepo for a full-stack project using Node.js + Express on the backend and a React app frontend (with CRA). If you get it, it very likely means that your application is not running with the PnP resolver, meaning that your require calls won’t be able to load files from your dependencies (since the node_modules needed for the regular Node resolution won’t have been generated). This error message is not generated by Plug’n’Play. This problem typically isn’t caused by Plug’n’Play itself, but rather by your application requiring something that doesn’t exist (under non-PnP mode you’d likely have a generic “Cannot find module” error). This error message means that Plug’n’Play was able to locate the package part of the require (so for example it understood that foo should be resolved into /usr/cache/yarn/foo-1.0.0), but couldn’t resolve the file part of the resolution (to use the same example, it couldn’t find an index.js file in /usr/cache/yarn/foo-1.0.0/). ![]() Couldn't find a suitable Node resolution for unqualified path The third option is typically meant as a way to unblock yourself, but please report it on the repository of the affected package and link them to this documentation (feel free to ping as well so that we can track those problems). In those circumstances, Yarn will allow Jest to access it even if it isn’t declared in its dependencies (we do this because this is the only case where this is safe: it isn’t possible for the top-level dependencies to be ambiguous). Or, finally, the jest-environment-jsdom package can be specified as dependency of the top-level package - usually your own. ![]() For example, Jest does something similar to require(`jest-environment-$)) (note that this is the recommended option, being unintrusive for users and a good idea in general) That being said, it might happen that the use is pseudo-legitimate. Since this behavior is unsafe and relies on the hoisting being done a certain way, Plug’n’Play doesn’t allow it. This error simply means that the specified package is requiring something without explicitly declaring it in its dependencies. is trying to require without it being listed in its dependencies The following page describes some common scenario one should be aware of, and provides some guidance to fix them. While we do our best to make Plug’n’Play a delightful experience, sometimes things might go wrong.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |