w3resource

Troubleshooting


Although the team at Plug'n'Play does their best to make Plug'n'Play a delightful experience, there are time when things might go wrong. This tutorial will describe some of the common scenarios that you should be aware of, as well as the guide to solve them.

<package name> is trying to require <package name> that is not listed in its dependencies

This error occurs when the specified package is requiring something without explicitly declaring it in its dependencies. Since this is an unsafe behavior which requires that the hoisting is done in a certain way, it is not allowed by Plug'n'Play.

However, it could be that the use is pseudo-legitimate. For instance, Jest will do something similar to require('jest-environment-${config.environment}') -In this case the aim is to use the package as it is provided by the package that sets up the package configuration. But it is still an unsafe behavior and has to be fixed in one of these three ways:

  • You will either have to modify the code, so that the user will become responsible for calling require.resolve('jest-environment-jsdom') (and then Jest will simply do require(config.environment))
  • Or you modify the code in order to use the paths option from require.resolve: require(require.resolve('jest-environment-${config.environment}', {paths:[config.projectPath]})) (it should be noted that this is the recommended option, since it will be unintrusive for users and will generally be a good idea)
  • Or, finally, you can specify the jest-environment-jsdom package as dependency of the top-level package - usually your own. In those circumstances, Yarn allows Jest to access it even if it is not declared in its dependencies (this is done because it is the only case where this is safe: it is not possible for the top-level dependencies to be ambiguous).

The third option is meant to unblock yourself, however, you should report it on the repository of the affected package and then link them to the documentation.

Could not find a suitable Node resolution for unqualified path <path>

When you get this error message it indicates that Plug'n'Play was able to locate the package part of the require( for instance it understand that bar should be resolved to /usr/cache/yarn/bar-1.0.0), but cannot resolve part of the resolution (for instance, it could not find a file named index.js in /usr/cache/yarn/bar-1.0.0/). This is typically not a problem caused by Plug'n'Play, instead it is your application requiring something that does not exist (under non-PnP mode you will most likely get a generic "Cannot find module" error).

Cannot find module <require-path>

This error is never generated by Plug'n'Play, if you ever get this error, it means that your application is not running with the PnP resolver, this means that your require calls won't be able to load files from your dependencies (This is because the node_modules folder that is needed for regular Node resolution would not have been generated).

You should ensure that you either run your code using NODE_OPTIONS="--require /path/to/.pnp.js"or you call it using yarn node which does the right thing transparently.

Previous: Overview of PnP
Next: The yarn workflow and creating a new project



Follow us on Facebook and Twitter for latest update.