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

@oakserver/oak causing ReadableStream" is not exported by "__vite-browser-external" #15900

Closed
7 tasks done
mkilpatrick opened this issue Feb 13, 2024 · 2 comments
Closed
7 tasks done

Comments

@mkilpatrick
Copy link

mkilpatrick commented Feb 13, 2024

Describe the bug

Using a custom plugin (that uses vite-plugin-node-polyfills) to build a file that uses @oakserver/oak gets the following build error:

error during build:
RollupError: "ReadableStream" is not exported by "__vite-browser-external", imported by "node_modules/@oakserver/oak/esm/_dnt.shims.js".
file: /home/projects/vitejs-vite-kbtffm/node_modules/@oakserver/oak/esm/_dnt.shims.js:9:9
 7: import { fetch, File, FormData, Headers, Request, Response } from "undici";
 8: export { fetch, File, FormData, Headers, Request, Response } from "undici";
 9: import { ReadableStream, TransformStream } from "stream/web";
             ^
10: export { ReadableStream, TransformStream } from "stream/web";
11: import { ErrorEvent } from "./node_shims.js";
    at Module.error (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/parseAst.js:468:30)
    at Module.error (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:12838:29)
    at Module.traceVariable (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:13275:29)
    at ModuleScope.findVariable (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:11692:39)
    at Identifier.bind (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:7274:40)
    at Property.bind (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:4698:23)
    at ObjectExpression.bind (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:4694:28)
    at VariableDeclarator.bind (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:4698:23)
    at VariableDeclaration.bind (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:4694:28)
    at Program.bind (/home/projects/vitejs-vite-kbtffm/node_modules/rollup/dist/es/shared/node-entry.js:4694:28)

In my repro see functionPlugin.js which is building functions/test.js.

Locally I was getting a slightly different error as my repro is slightly different. It was the same error as described in this issue.

Reproduction

https://stackblitz.com/edit/vitejs-vite-kbtffm?file=functions%2Ftest.js

Steps to reproduce

No response

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.14.0 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^5.1.1 => 5.1.1

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Feb 13, 2024

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red
Copy link
Member

Locally I was getting a slightly different error as my repro is slightly different.

This is because you are placing vite-plugin-node-polyfills inside the config hook.
https://vitejs.dev/guide/api-plugin.html#config:~:text=User%20plugins%20are%20resolved%20before%20running%20this%20hook%20so%20injecting%20other%20plugins%20inside%20the%20config%20hook%20will%20have%20no%20effect.

The error is caused by vite-plugin-node-polyfills. It's resolving stream/web to stream-browserify/web that doesn't exist. (related: davidmyersdev/vite-plugin-node-polyfills#48)

Closing as it's not a bug in Vite.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants