Reputation: 207
I am building a web app in svelte ( which uses rollup ). I am using a 3rd party SDK which implements this API https://github.com/near/near-api-js . This API imports JSON at some point. Because of this, I had to install @rollup/plugin-json
.
I am importing it into my rollup.config.js as follows...
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
}
};
From here I am calling the 3rd Party SDK in /Services/FluxProvider.js
like this...
script
tag of App.js
... same results when calling one of the SDK methods 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();
After doing this, I get the following error...
(!) 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
I have done the following...
cannot find 'fs'
I am not sure why this is happening and after asking a few people, they aren't sure either.
IMPORTANT NOTE: This SDK works perfectly fine in my create-react-app project, but not in svelte webpack or svelte rollup.
Any idea's / suggestions welcome.
Upvotes: 1
Views: 752
Reputation: 1109
I tried the same thing with a webpack template
npx degit sveltejs/template-webpack svelte-app
it didn't blare with these errors, I suspect rollup isn't friendly with the fluxsdk packaged with webpack.
With the webpack template, there are no errors and svelte seems to compile just fine.
IMPORTANT NOTE: This SDK works perfectly fine in my create-react-app project, but not in svelte webpack or svelte rollup.
CRA uses webpack too.
Upvotes: 1