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

[Bug]: esm.sh uses browser build on Deno SSR with v1.1.0 #426

Closed
kkga opened this issue Dec 18, 2022 · 8 comments · Fixed by #425
Closed

[Bug]: esm.sh uses browser build on Deno SSR with v1.1.0 #426

kkga opened this issue Dec 18, 2022 · 8 comments · Fixed by #425
Labels
🐞 Bug Bug or Bug fixes

Comments

@kkga
Copy link

kkga commented Dec 18, 2022

Reproduction

Here's a minimal example to reproduce on Deno playground.
https://dash.deno.com/playground/twind-1x-ssr-rendering (try changing the import to @twind/core@1.1.0 to see the resulting error).

Describe the bug

I've been using twind v1.0.3 for server-side rendering on Deno with inline().

Trying to upgrade to the latest twind v1.1.0 via esm.sh (https://esm.sh/@twind/core@1.1.0), but getting an error when calling setup():

error: Uncaught ReferenceError: document is not defined
    at Lt (https://esm.sh/v99/@twind/core@1.1.0/deno/core.js:2:15598)
    at le (https://esm.sh/v99/@twind/core@1.1.0/deno/core.js:2:15817)
    at qt (https://esm.sh/v99/@twind/core@1.1.0/deno/core.js:2:16738)
    at ae (https://esm.sh/v99/@twind/core@1.1.0/deno/core.js:2:17665)

Severity

blocking an upgrade

System Info

Running on Deno Deploy SSR with `inline()`

Additional Information

Discord: https://discord.com/channels/798324011980423188/929266391645839360/1054016301149999115

@kkga kkga added the 🐞 Bug Bug or Bug fixes label Dec 18, 2022
@kkga kkga changed the title [Bug]: esm.sh uses browser build with v1.1.0 [Bug]: esm.sh uses browser build on Deno SSR with v1.1.0 Dec 18, 2022
@sastan
Copy link
Collaborator

sastan commented Dec 19, 2022

The dev versions for 1.0.3 fails as well (https://esm.sh/@twind/core@1.0.3?dev). In the top you see that @twind/core/core.browser.js is used. Don't know whats going on here.

Here is the package.json for core:

{
  "name": "@twind/core",
  "version": "1.1.0",
  "type": "module",
  "main": "./core.cjs",
  "exports": {
    ".": {
      "types": "./core.d.ts",
      "development": {
        "esnext": "./core.esnext.dev.js",
        "module": "./core.dev.js",
        "worker": "./core.dev.js",
        "browser": "./core.browser.dev.js",
        "script": "./core.global.dev.js",
        "node": {
          "import": "./core.dev.mjs",
          "require": "./core.dev.cjs"
        },
        "default": "./core.dev.js"
      },
      "esnext": "./core.esnext.js",
      "module": "./core.js",
      "worker": "./core.js",
      "browser": "./core.browser.js",
      "script": "./core.global.js",
      "node": {
        "import": "./core.mjs",
        "require": "./core.cjs"
      },
      "default": "./core.js"
    },
    "./package.json": "./package.json"
  },
}

After reading https://github.com/ije/esm.sh/blob/main/server/nodejs.go#L500-L502 it should have picked "./core.js"from exports['.'].module. I'll will create a debug package and see when esm.sh is returning what.

But that will take me at least a day. Sorry...

@alshdotme
Copy link

Not sure if this is related, but on 1.10 and 1.0.3 I am also having issues when using SSR. However I am using React with AWS Lambda for SSR not Deno. I'm getting the following:

v1.1.0

{'errorType': 'Runtime.UserCodeSyntaxError', 'errorMessage': "SyntaxError: Unexpected token '||='", 'trace': ["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '&&='", '    at _loadUserApp (/var/runtime/UserFunction.js:218:13)', '    at Object.module.exports.load (/var/runtime/UserFunction.js:279:17)', '    at Object.<anonymous> (/var/runtime/index.js:43:34)', '    at Module._compile (internal/modules/cjs/loader.js:1085:14)', '    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)', '    at Module.load (internal/modules/cjs/loader.js:950:32)', '    at Function.Module._load (internal/modules/cjs/loader.js:790:12)', '    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)', '    at internal/main/run_main_module.js:17:47']}

v1.0.3

{'errorType': 'Runtime.UserCodeSyntaxError', 'errorMessage': "SyntaxError: Unexpected token '&&='", 'trace': ["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '&&='", '    at _loadUserApp (/var/runtime/UserFunction.js:218:13)', '    at Object.module.exports.load (/var/runtime/UserFunction.js:279:17)', '    at Object.<anonymous> (/var/runtime/index.js:43:34)', '    at Module._compile (internal/modules/cjs/loader.js:1085:14)', '    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)', '    at Module.load (internal/modules/cjs/loader.js:950:32)', '    at Function.Module._load (internal/modules/cjs/loader.js:790:12)', '    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)', '    at internal/main/run_main_module.js:17:47']}

@sastan
Copy link
Collaborator

sastan commented Dec 20, 2022

Not sure if this is related, but on 1.10 and 1.0.3 I am also having issues when using SSR. However I am using React with AWS Lambda for SSR not Deno.

This seems to be unrelated but can be fixed in the same release. The issue here is that the module export condition that is being used is using es2020 for its transpilation where logical shorthands (&&= or ||=) are not transpiled. To fix that you should enable transpilation of node_modules for all twind packages during bundling of your app.

To prevent this issue in the future I will downgrade the module export condition transpilation target to es2019.

@sastan
Copy link
Collaborator

sastan commented Dec 20, 2022

I think both issues are solved in the next release. Could you please try the next dist tag (eg @twind/core@next)? A list of specific releases can be found here: https://github.com/tw-in-js/twind/actions/runs/3738559044/attempts/1#summary-10201193157

@sastan
Copy link
Collaborator

sastan commented Dec 20, 2022

@kkga Here is the playground I used for testing: https://dash.deno.com/playground/dry-mouse-49

@alshdotme
Copy link

@sastan makes sense, I thought it would be something like that. Thank you for clarifying. I will upgrade now and reply back here.

@sastan
Copy link
Collaborator

sastan commented Dec 20, 2022

I published these changes in the new release. You can try the latest stable versions now.

@kkga
Copy link
Author

kkga commented Dec 20, 2022

Confirming that it works now, thanks! 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants