use node `stream` or workaround for sveltekit in CF?

i'm using sveltekit with CF. i'm having an issue when i import the stl npm package with import stl from 'stl';, i can run locally but it breaks on CloudFlare with this error (https://www.npmjs.com/package/stl)
[ERROR] Could not resolve "stream"
...
08:40:21.555      The package "stream" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
08:40:21.556    
08:40:21.557    ✘ [ERROR] Could not resolve "stream"
08:40:21.557    
08:40:21.557        node_modules/through/index.js:1:21:
08:40:21.557          1 │ var Stream = require('stream')
08:40:21.557            ╵                      

the advice i'm getting from Cursor.sh (GPT-4) is below:
The error message indicates that the package stream is not found in your project's dependencies. The stream module is a built-in Node.js module, and it seems like your project is trying to bundle it for the browser, which is causing the error.

To fix this issue, you can use the resolve option in Vite's configuration to alias the stream module to a browser-compatible version. You can use the stream-browserify package for this.

First, install stream-browserify:
npm install --save stream-browserify

Then, update your vite.config.js file to include the following:
import { defineConfig } from 'vite'

export default defineConfig({
  // other config
  resolve: {
    alias: {
      stream: 'stream-browserify'
    }
  }
})


This will tell Vite to use stream-browserify whenever stream is imported, which should resolve the error.
---

this seems like an odd issue, maybe i just need to update node? is stream-browserify really necessary? (following these instructions still gives the same error)
npm
STL to Array of verts and vice versa. Latest version: 1.1.1, last published: 9 years ago. Start using stl in your project by running npm i stl. There are 11 other projects in the npm registry using stl.
Was this page helpful?