Skip to content

[js/web] fix nodejs detection#16400

Merged
fs-eire merged 2 commits into
mainfrom
fs-eire/web-fix-check-node
Jun 20, 2023
Merged

[js/web] fix nodejs detection#16400
fs-eire merged 2 commits into
mainfrom
fs-eire/web-fix-check-node

Conversation

@fs-eire
Copy link
Copy Markdown
Contributor

@fs-eire fs-eire commented Jun 18, 2023

Description

We used to use typeof fetch === 'undefined' as condition to detect the environment is Node.js or not. Before Node.js v18, this works. However, in Node.js v18, it introduced fetch function, so this check does not work any more.

This PR changes the condition to check whether process, process.versions and process.versions.node exists.

Checking whether process exists is not enough. This is because in some configuration, webpack may polyfill nodejs's process.

Comment thread js/web/lib/onnxjs/session.ts
@fs-eire fs-eire merged commit b8917ad into main Jun 20, 2023
@fs-eire fs-eire deleted the fs-eire/web-fix-check-node branch June 20, 2023 07:21
siweic0 pushed a commit to siweic0/onnxruntime-web that referenced this pull request May 9, 2024
### Description
We used to use `typeof fetch === 'undefined'` as condition to detect the
environment is Node.js or not. Before Node.js v18, this works. However,
in Node.js v18, it introduced `fetch` function, so this check does not
work any more.

This PR changes the condition to check whether `process`,
`process.versions` and `process.versions.node` exists.

Checking whether `process` exists is not enough. This is because in some
configuration, webpack may polyfill nodejs's process.
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 this pull request may close these issues.

3 participants