Skip to content

Error when building ESM project #732

@stayradiated

Description

@stayradiated

First up, just wanted to say how much I love ncc, it makes distributing JS code a breeze. Thank you!

I've just upgraded to v0.29.0, but when I try to build a project that uses ESM modules (type: "module" and .js extensions) I get this error:

TypeError: Cannot read property 'toString' of undefined
    at finalizeHandler (/project/node_modules/.pnpm/@[email protected]/node_modules/@vercel/ncc/dist/ncc/index.js.cache.js:37:1866714)

Looking at ./src/index.js it seems the issue is related to calling pjsonPath.source.toString().
When I log pgjsonPath I just get the string package.json.

      const pjsonPath = (baseDir === '.' ? '' : baseDir) + 'package.json';
      if (assets[pjsonPath])
        assets[pjsonPath].source = JSON.stringify(Object.assign(JSON.parse(pjsonPath.source.toString()), { type: 'module' }));

https://github.com/vercel/ncc/blob/main/src/index.js#L532-L537

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions