Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when building ESM project #732

Closed
stayradiated opened this issue Jul 22, 2021 · 1 comment · Fixed by #733
Closed

Error when building ESM project #732

stayradiated opened this issue Jul 22, 2021 · 1 comment · Fixed by #733
Labels
bug Something isn't working

Comments

@stayradiated
Copy link

stayradiated commented Jul 22, 2021

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/@vercel+ncc@0.29.0/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

@styfle styfle added the bug Something isn't working label Jul 22, 2021
@guybedford
Copy link
Contributor

Thanks for the clear report and glad to hear the project is working well for you otherwise.

This should be resolved in #733, may still take a few hours for the merge and release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants