question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code

See original GitHub issue

Describe the bug When using Vite with Vue, I got this error when importing the Notion-Client.

Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code.

To Reproduce Node version: 16.7.0 Notion JS library version: 0.4.1

Steps to reproduce the behavior:

  1. Setup a vite-project pnpm dlx create-vite
  2. Choose vue-ts
  3. Install Notion SDK pnpm install @notionhq/client
  4. Insert Code Snippet
<script setup lang="ts">
import { Client } from '@notionhq/client'

const notion = new Client({ auth: process.env.NOTION_ACCESS_TOKEN })

</script>

<template>
  <div>
   Test
  </div>
</template>

Expected behavior It should display on localhost:3000 Test without errors.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
leiax00commented, Nov 24, 2021

@jolo-dev try excluding the dependency from the vite optimization by adding the following to your vite.config.js file. it worked for me!

export default defineConfig({
  //...
  optimizeDeps: {
    exclude: ['@notionhq/client']
  },
  //...
})

read more here!

Did you actually try it? It won’t work even if you add that.

It solved the issue for me but it brings out other problems in my case

Same for me, now I have Uncaught SyntaxError: The requested module '/node_modules/@notionhq/client/build/src/index.js?v=fcc54f13' does not provide an export named 'Client'

me too, Is there a new solution now?

1reaction
shug0commented, Oct 29, 2021

@jolo-dev try excluding the dependency from the vite optimization by adding the following to your vite.config.js file. it worked for me!

export default defineConfig({
  //...
  optimizeDeps: {
    exclude: ['@notionhq/client']
  },
  //...
})

read more here!

Did you actually try it? It won’t work even if you add that.

It solved the issue for me but it brings out other problems in my case

Same for me, now I have Uncaught SyntaxError: The requested module '/node_modules/@notionhq/client/build/src/index.js?v=fcc54f13' does not provide an export named 'Client'

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module "stream" has been externalized for browser ... - GitHub
The browser will say Uncaught Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code.
Read more >
Module "path" has been externalized for browser compatibility
Module "path" has been externalized for browser compatibility and cannot be accessed in client code. Solution. Steps: Install "path-browserify":.
Read more >
Uncaught Error: Module "events" has been externalized for ...
Error : Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code. git repo link : ...
Read more >
Module "stream" has been externalized for browser compatibility
The Airtable npm module is only for Node, not browsers. You need to put the code related to that module in a server...
Read more >
Module "stream" has been externalized for browser compatibility
I'm trying to access the Airtable API with Sveltekit and am running into the following error: Module "stream" has been externalized for browser...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found