After upgrading to Yarn 3.0 with Yarn Plug'n'Play (throw out node_modules), I started having issues with filename resolution when starting Node.
After successfully starting server.js
it tries to resolve the first imported file in the project, called util.js
, but path resolution fails unless I explicitly add .js
to the filename. I would prefer to not have to update all paths project-wide.
Can I make Yarn and Node resolve the .js
file extensions automatically?
Yarn 3.1.0
, Node 17.0.1
.
yarn node server.js # Automatically uses Yarn's .pnp.cjs, right?
// server.js excerpt
import util from "/tools/util"; // <-- 🛑 No worky
import util from "/tools/util.js"; // <-- ✅ Worky
The error message:
/Users/me/repo/.pnp.cjs:22839
return Object.defineProperties(new Error(message), {
^
Error: Qualified path resolution failed - none of those files can be found on the disk.
Source path: /Users/me/repo/server/util
Not found: /Users/me/repo/server/util
at internalTools_makeError (/Users/me/repo/.pnp.cjs:22839:34)
at resolveUnqualified (/Users/me/repo/.pnp.cjs:24238:13)
at resolveRequest (/Users/me/repo/.pnp.cjs:24271:14)
at Object.resolveRequest (/Users/me/repo/.pnp.cjs:24343:26)
at resolve$1 (file:///Users/me/repo/.pnp.loader.mjs:205:25)
at ESMLoader.resolve (node:internal/modules/esm/loader:422:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:222:40)
at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:40)
at link (node:internal/modules/esm/module_job:75:36)
3.1.1
and node17.4.0
. Will report back here when I figure it out. – Rearrange