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 during SSR #9242

Closed
2 of 6 tasks
feus4177 opened this issue May 2, 2024 · 6 comments
Closed
2 of 6 tasks

Error during SSR #9242

feus4177 opened this issue May 2, 2024 · 6 comments
Assignees
Labels
4 - verified Issues that have been released and confirmed resolved. bug Bug reports for broken functionality. Issues should include a reproduction of the bug. calcite-components Issues specific to the @esri/calcite-components package. impact - p3 - not time sensitive User set priority impact status of p3 - not time sensitive spike Issues that cannot be estimated well enough until the team has done further research

Comments

@feus4177
Copy link

feus4177 commented May 2, 2024

Check existing issues

Actual Behavior

Throws an error during import.

Expected Behavior

No errors are thrown during import.

Reproduction Sample

SSR problem

Reproduction Steps

Setup a default vite 5.1 build with the following added to the vite config

  ssr: {
    noExternal: [
      '@esri/calcite-components',
      '@stencil/core',
    ],
  },

Reproduction Version

2.8.0

Relevant Info

MacOS

ReferenceError: navigator is not defined
    at getUserAgentData (./node_modules/.pnpm/@esri+calcite-components@2.8.0/node_modules/@esri/calcite-components/dist/components/src/utils/browser.ts:9:5)

Regression?

No response

Priority impact

p4 - not time sensitive

Impact

Unable to use calcite-components. Will probably have to use a different library.

Calcite package

  • @esri/calcite-components
  • @esri/calcite-components-angular
  • @esri/calcite-components-react
  • @esri/calcite-design-tokens
  • @esri/eslint-plugin-calcite-components

Esri team

N/A

@feus4177 feus4177 added 0 - new New issues that need assignment. bug Bug reports for broken functionality. Issues should include a reproduction of the bug. needs triage Planning workflow - pending design/dev review. labels May 2, 2024
@github-actions github-actions bot added impact - p3 - not time sensitive User set priority impact status of p3 - not time sensitive calcite-components Issues specific to the @esri/calcite-components package. labels May 2, 2024
@geospatialem geospatialem added the need more info Issues that are missing information and/or a clear, actionable description. label Jun 4, 2024
@geospatialem
Copy link
Member

@feus4177 Can you supply a reproduction sample or a scaffolding command for us to diagnose further?

We're currently blocked by a Stencil issue, ionic-team/stencil#4010, so we may be unable to mitigate depending on the instance.

@geospatialem
Copy link
Member

@feus4177 Following up if you can supply us with a repro sample to diagnose further.

@feus4177
Copy link
Author

@geospatialem, sorry it took so long to get back to you. Here is a repo with a minimal reproduction. From the root directory of the repo, run npm run dev and open up the localhost URL that it prints out.

I now get a slightly different error: ReferenceError: window is not defined. I seem to recall that I was able to get past this (I think by importing from a slightly different path).

The only unusual aspect of my code is the update to the vite.config.js file where I added the

  ssr: {
   noExternal: [
     '@esri/calcite-components',
     '@stencil/core',
   ],
 },

as mentioned above. Without that config, I get an error about importing CommonJS modules from an ES module.

@geospatialem geospatialem added spike Issues that cannot be estimated well enough until the team has done further research and removed need more info Issues that are missing information and/or a clear, actionable description. labels Jul 11, 2024
@geospatialem geospatialem added this to the 2024-07-30 - Jul Release milestone Jul 11, 2024
@geospatialem geospatialem removed the needs triage Planning workflow - pending design/dev review. label Jul 11, 2024
@geospatialem geospatialem added 1 - assigned Issues that are assigned to a sprint and a team member. and removed 0 - new New issues that need assignment. labels Jul 11, 2024
@noahmulfinger
Copy link
Contributor

@benelan @geospatialem I came upon this same issue when trying to use the Custom Elements build in Gatsby, and I created another test repo that might be useful: https://github.com/noahmulfinger/gatsby-calcite-components

It seems that the SSR fails due to two files using browser-only objects:

If I remove the references in the two files (and replace them with dummy strings/classes), there are no longer any SSR errors.

@benelan benelan added 2 - in development Issues that are actively being worked on. and removed 1 - assigned Issues that are assigned to a sprint and a team member. labels Jul 30, 2024
@benelan benelan linked a pull request Jul 30, 2024 that will close this issue
benelan added a commit that referenced this issue Jul 30, 2024
**Related Issue:** #9242

## Summary

Add additional browser checks to resolve some SSR errors that Stencil's
`Build.isBrowser` util doesn't catch.
@benelan benelan added 3 - installed Issues that have been merged to master branch and are ready for final confirmation. and removed 2 - in development Issues that are actively being worked on. labels Jul 30, 2024
@github-actions github-actions bot assigned geospatialem and DitwanP and unassigned benelan Jul 30, 2024
Copy link
Contributor

Installed and assigned for verification.

calcite-admin pushed a commit that referenced this issue Jul 30, 2024
**Related Issue:** #9242

## Summary

Add additional browser checks to resolve some SSR errors that Stencil's
`Build.isBrowser` util doesn't catch.
@jcfranco
Copy link
Member

Verified locally.

@jcfranco jcfranco added 4 - verified Issues that have been released and confirmed resolved. and removed 3 - installed Issues that have been merged to master branch and are ready for final confirmation. labels Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - verified Issues that have been released and confirmed resolved. bug Bug reports for broken functionality. Issues should include a reproduction of the bug. calcite-components Issues specific to the @esri/calcite-components package. impact - p3 - not time sensitive User set priority impact status of p3 - not time sensitive spike Issues that cannot be estimated well enough until the team has done further research
Projects
None yet
Development

No branches or pull requests

6 participants