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

Platform is undefined in dev mode #8230

Closed
chrskerr opened this issue Dec 20, 2022 · 1 comment · Fixed by #8232
Closed

Platform is undefined in dev mode #8230

chrskerr opened this issue Dec 20, 2022 · 1 comment · Fixed by #8232

Comments

@chrskerr
Copy link
Contributor

chrskerr commented Dec 20, 2022

Describe the bug

In the docs (here) the default type for Platform is {}, but in dev it is coming through as undefined.

This makes type safety harder, since TS doesn't enforce an is-object check before attempting to access properties.

My preference would like to default Platform to an empty object, rather than updating the type to allow undefined.

This is an issue for us since adapter-node will only apply during production builds and as such during dev the Platform object is undefined.

Reproduction

Open repo https://github.com/chrskerr/sveltekit-platform-demo, and start in dev mode

Open the app in any browser, and you'll see 'undefined' printed into the terminal as the result of console.log(typeof event.platform) from hooks.server.ts

VSCode believes the type of event.platform to be Readonly or Readonly<{}>, meaning the below fails TS because 'something' doesn't exist on event.platform (correct) but it doesn't catch that event.platform is maybe undefined

Screenshot 2022-12-20 at 11 50 20 am

Logs

No response

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 266.11 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.18.1 - ~/.nvm/versions/node/v16.18.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v16.18.1/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Firefox: 107.0
    Safari: 16.2
  npmPackages:
    @sveltejs/adapter-auto: ^1.0.0 => 1.0.0 
    @sveltejs/adapter-node: ^1.0.0 => 1.0.0 
    @sveltejs/kit: ^1.0.0 => 1.0.1 
    svelte: ^3.54.0 => 3.55.0 
    vite: ^4.0.0 => 4.0.2

Severity

annoyance

Additional Information

No response

@chrskerr chrskerr changed the title Platform is undefined in dev mode, not {} Platform is undefined in dev mode Dec 20, 2022
@gtm-nayan gtm-nayan linked a pull request Dec 21, 2022 that will close this issue
5 tasks
@paukuman
Copy link

alternative, using a npm run pages:preview

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.

2 participants