[英]Svelte: Uncaught ReferenceError: exports is not defined
我正在嘗試在 Svelte 應用程序中使用dgraph-js-http 。
我面臨的最初錯誤是:
Uncaught ReferenceError: buffer is not defined
<anonymous> http://localhost:5000/build/bundle.js:6947
我將此包括在內,因為也許我對此的解決方案不是最好的,並且希望有一種方法可以同時解決此問題和當前的阻止程序問題。
然而,經過反復試驗(見下文了解我嘗試過的各種方法)后,我現在陷入困境。
解決上述錯誤后,我現在被這個錯誤阻止了:
Uncaught ReferenceError: define is not defined
以下均無效。
<script src="https://bundle.run/stream@0.0.2"></script>
到 index.htmlnpm install stream
import * as Stream from "stream"
添加到 App.svelte 文件import * as Stream from "stream"
添加到 stores.js 文件preferBuiltins:true
到rollup.config.js
npm install --save-dev rollup-plugin-node-polyfills
preferBuiltins:false
添加到rollup.config.js
。 這解決了先前的錯誤並導致了新錯誤: Uncaught ReferenceError: define is not defined
npm install --save define
。 現在,這會導致當前的阻止程序:Uncaught ReferenceError: exports is not defined
我想你錯過了type: "module"
屬性。 這里type屬性表示javascript解釋器的類型是commonjs還是babel。 type: "module"
表示你將使用 babel 作為 ECMA 腳本解釋器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.