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

wrangler publish fails when ESModule is used #252

Closed
Kynson opened this issue Jan 16, 2022 · 9 comments · Fixed by #258
Closed

wrangler publish fails when ESModule is used #252

Kynson opened this issue Jan 16, 2022 · 9 comments · Fixed by #258
Assignees

Comments

@Kynson
Copy link

Kynson commented Jan 16, 2022

Hello,

I got this error when publishing my ESModule project: Cannot read properties of undefined (reading '1')

I reproduce the issue with the following files:

test.js

import './another.js'

console.log('This is a test')

another.js

console.log('This is another module')

wragnler.toml

name = 'test'
type = 'javascript'
account_id = '<ACCOUNT_ID>'
zone_id = '<ZONE_ID>'

compatibility_date = '2021-11-10'

[build.upload]
format = 'modules'
main = './test.js'

And then run npx wrangler@beta publish

The issue does not exist if another.js is not imported. I am not sure this is a bug or it is because v2 is still in beta and ESModule is not yet supported

Thank you.

@Electroid Electroid added the bug label Jan 16, 2022
@petebacondarwin
Copy link
Contributor

petebacondarwin commented Jan 17, 2022

@petebacondarwin
Copy link
Contributor

You can work around this by providing the entry-point script at the command line:

npm wrangler publish index.js

@petebacondarwin petebacondarwin self-assigned this Jan 17, 2022
@threepointone
Copy link
Contributor

I think this might already be fixed in main after #196, but we should verify

@petebacondarwin
Copy link
Contributor

#196 didn't help.

@petebacondarwin
Copy link
Contributor

Working on a fix...

petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jan 18, 2022
The `publish` command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the `metafile.inputs` to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the `metadata.outputs` object will only contain one element that has the `entrypoint` property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes cloudflare#252
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jan 18, 2022
The `publish` command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the `metafile.inputs` to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the `metadata.outputs` object will only contain one element that has the `entrypoint` property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes cloudflare#252
@wesbos
Copy link

wesbos commented Jan 18, 2022

Hitting this right now as well. The temp fix doesn't seem to work - same error. Is there another workaround?

@threepointone
Copy link
Contributor

We just published a fix, could you try again with wrangler@beta?

@wesbos
Copy link

wesbos commented Jan 18, 2022

wow awesome! Worked great - thanks a million

@threepointone
Copy link
Contributor

Closing this, working on the reopened issue #78 and the deeper fix with #258.

petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jan 19, 2022
The `publish` command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the `metafile.inputs` to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the `metadata.outputs` object will only contain one element that has the `entrypoint` property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes cloudflare#252
petebacondarwin added a commit to petebacondarwin/wrangler2 that referenced this issue Jan 19, 2022
The `publish` command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the `metafile.inputs` to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the `metadata.outputs` object will only contain one element that has the `entrypoint` property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes cloudflare#252
petebacondarwin added a commit that referenced this issue Jan 19, 2022
The `publish` command was failing when the entry-point was specified in the wrangler.toml file and the entry-point imported another file.

This was because we were using the `metafile.inputs` to guess the entry-point file path. But the order in which the source-files were added to this object was not well defined, and so we could end up failing to find a match.

This fix avoids this by using the fact that the `metadata.outputs` object will only contain one element that has the `entrypoint` property - and then using that as the entry-point path. For runtime safety, we now assert that there cannot be zero or multiple such elements.

Fixes #252
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants