-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hi, me again 😄 Not to add more stuff to #8 as there's a lot already.
Issue:
The "path" argument must be of type string. Received an instance of Object
Quick stack:
at Resolver.getFilePathFromPackageJson (../../node_modules/babel-plugin-transform-barrels/src/resolver.js:141:52)
at Resolver.resolveAbsFilePath (../../node_modules/babel-plugin-transform-barrels/src/resolver.js:113:30)
at Resolver.resolveNodeModules (../../node_modules/babel-plugin-transform-barrels/src/resolver.js:94:39)
at Resolver.resolve (../../node_modules/babel-plugin-transform-barrels/src/resolver.js:52:29)
at ../../node_modules/babel-plugin-transform-barrels/src/barrel.js:233:45
at Array.forEach (<anonymous>)
The investigation tells me:
- the
cjsModuleand/oresmModuleare objects, not paths - it fails on e.g.
date-fnspackage - example
exportsObj:
{
absCjsFile: { types: './index.d.cts', default: './index.cjs' },
absEsmFile: { types: './index.d.ts', default: './index.js' }
}- coming from here: https://github.com/date-fns/date-fns/blob/main/package.json#L23-L32
Should be easy to fix. Maybe a typeof cjsModule === 'string' check and optional access like cjsModule?.default or something? Not sure what's the exact package.json > exports standard.
I imagine something like:
- const absCjsModule = cjsModule && ospath.join(path, cjsModule);
- const absEsmModule = esmModule && ospath.join(path, esmModule);
+ const cjsPath = typeof cjsModule === 'string' ? cjsModule : cjsModule?.default;
+ const esmPath = typeof esmModule === 'string' ? esmModule : esmModule?.default;
+ const absCjsModule = cjsPath && ospath.join(path, cjsPath);
+ const absEsmModule = esmPath && ospath.join(path, esmPath);
Metadata
Metadata
Assignees
Labels
No labels