首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Svelte +汇总错误[!]SyntaxError:在严格模式下删除局部变量(8:8)?

Svelte +汇总错误[!]SyntaxError:在严格模式下删除局部变量(8:8)?
EN

Stack Overflow用户
提问于 2021-02-17 18:37:46
回答 1查看 428关注 0票数 1

我正在构建一个svelte的web应用程序(它使用汇总)。我正在使用一个第三方SDK,它实现了这个API https://github.com/near/near-api-js。这个API在某个时候导入JSON。因此,我不得不安装@rollup/plugin-json

我将它导入我的rollup.config.js中,如下所示..。

代码语言:javascript
复制
import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-css-only';
import json from '@rollup/plugin-json';

const production = !process.env.ROLLUP_WATCH;

function serve() {
    let server;

    function toExit() {
        if (server) server.kill(0);
    }

    return {
        writeBundle() {
            if (server) return;
            server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
                stdio: ['ignore', 'inherit', 'inherit'],
                shell: true
            });

            process.on('SIGTERM', toExit);
            process.on('exit', toExit);
        }
    };
}

export default {
    input: 'src/main.js',
    output: {
        sourcemap: true,
        format: 'cjs',
        name: 'app',
        file: 'public/build/bundle.js',
    },
    plugins: [
        svelte({
            compilerOptions: {
                // enable run-time checks when not in production
                dev: !production
            }
        }),
        // we'll extract any component CSS out into
        // a separate file - better for performance
        css({ output: 'bundle.css' }),

        // If you have external dependencies installed from
        // npm, you'll most likely need these plugins. In
        // some cases you'll need additional configuration -
        // consult the documentation for details:
        // https://github.com/rollup/plugins/tree/master/packages/commonjs
        resolve({
            browser: true,
            dedupe: ['svelte']
        }),
        commonjs(),
        json(),

        // In dev mode, call `npm run start` once
        // the bundle has been generated
        !production && serve(),

        // Watch the `public` directory and refresh the
        // browser on changes when not in production
        !production && livereload('public'),

        // If we're building for production (npm run build
        // instead of npm run dev), minify
        production && terser()
    ],
    watch: {
        clearScreen: false
    }
};

在这里,我打电话给/Services/FluxProvider.js中的第三方SDK .

  • 备注:我也在App.jsscript标签上试过这个.调用SDK方法之一

时的相同结果

代码语言:javascript
复制
 export let name;

  import FluxSdk from "@fluxprotocol/amm-sdk";

  async function main() {
    const sdk = new FluxSdk();
    await sdk.connect();

    console.log("Connected and ready to go!");
  }

  main();

这样做后,我得到以下错误..。

(!) Plugin node-resolve: preferring built-in module 'util' over local alternative at 'C:\Users\Ethan\node_modules\util\util.js', pass 'preferBuiltins: false' to disable this behavior or 'preferBuiltins: true' to disable this warning [!] (plugin commonjs) SyntaxError: Deleting local variable in strict mode (8:8) in C:\Users\Ethan\Desktop\AMM-test\node_modules\u3\lib\cache.js

我做了以下工作..。

  1. 让SDK (不是近API开发人员,而是实现近Api的SDK )来看看。他找不到原因。
  2. i试图在Svelte-webpack中重建这个web应用程序,但这只是给出了其他一些问题,比如

我不知道为什么会这样,在问了几个人之后,他们也不确定。

重要注意:这个SDK在我的创建-反应-应用程序项目中工作得很好,但不是在svelte webpack或svelte汇总中。

欢迎任何想法/建议。

EN

回答 1

Stack Overflow用户

发布于 2021-03-29 06:20:56

我用webpack模板做了同样的尝试。

npx degit sveltejs/template-webpack svelte-app

它并没有指责这些错误,我怀疑汇总与webpack一起包装的fluxsdk并不友好。

使用webpack模板,没有错误,svelte似乎编译得很好。

重要注意事项:这个SDK在我的创建反应应用项目中非常好,但在svelte webpack或svelte汇总中没有。

CRA也使用webpack。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66248017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档