Skip to content

The "path" argument must be of type string. Received an instance of Object #11

@rtrembecky

Description

@rtrembecky

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 cjsModule and/or esmModule are objects, not paths
  • it fails on e.g. date-fns package
  • example exportsObj:
{
  absCjsFile: { types: './index.d.cts', default: './index.cjs' },
  absEsmFile: { types: './index.d.ts', default: './index.js' }
}

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions