背景
我正在尝试使用 dgraph-js-http在 Svelte 应用程序中。
错误
我面临的最初错误是:
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.html npm 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"
package.json 中的属性。这里的type属性代表了javascript解释器的类型是commonjs还是babel。 type: "module"
表示你将使用 babel 作为 ECMA 脚本解释器。
关于javascript - Svelte:未捕获的 ReferenceError:未定义导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67963009/