antony / sveltekit-adapter-browser-extension

Build browser extensions with Svelte (early prototype)
160 stars 19 forks source link

Cannot read properties of undefined (reading 'rimraf') #7

Closed jagmeethanspal closed 2 years ago

jagmeethanspal commented 2 years ago

Using a default Svelte sitekit demo example code. With earlier versions of Svelte (without Sitekit) I used the generated outputs in the 'build/public' directory (along with some additions like manifest.json) to use it as an extension.

But, with the new sitekit versions, thinking of using your adaptor for a Browser Extention, but it errors out with the following logs:

npm run build

> screener@0.0.1 build
> svelte-kit build

vite v2.8.2 building for production...
✓ 34 modules transformed.
.svelte-kit/output/client/ext/assets/svelte-logo-87df40b8.svg                           1.85 KiB
.svelte-kit/output/client/ext/assets/fira-mono-cyrillic-400-normal-c7d433fd.woff2       8.89 KiB
.svelte-kit/output/client/ext/assets/fira-mono-cyrillic-ext-400-normal-3df7909e.woff2   15.40 KiB
.svelte-kit/output/client/ext/assets/fira-mono-greek-ext-400-normal-9e2fe623.woff2      7.33 KiB
.svelte-kit/output/client/ext/assets/fira-mono-greek-400-normal-a8be01ce.woff2          10.27 KiB
.svelte-kit/output/client/ext/assets/fira-mono-latin-ext-400-normal-6bfabd30.woff2      11.10 KiB
.svelte-kit/output/client/ext/assets/fira-mono-latin-400-normal-e43b3538.woff2          15.90 KiB
.svelte-kit/output/client/ext/assets/fira-mono-all-400-normal-1e3b098c.woff             75.55 KiB
.svelte-kit/output/client/ext/manifest.json                                             2.51 KiB
.svelte-kit/output/client/ext/pages/index.svelte-92dd2217.js                            4.08 KiB / gzip: 1.69 KiB
.svelte-kit/output/client/ext/start-d2bbeb70.js                                         23.34 KiB / gzip: 7.95 KiB
.svelte-kit/output/client/ext/error.svelte-6f6d00da.js                                  1.56 KiB / gzip: 0.75 KiB
.svelte-kit/output/client/ext/pages/__layout.svelte-1fdcf5b9.js                         4.76 KiB / gzip: 1.85 KiB
.svelte-kit/output/client/ext/pages/about.svelte-64b29582.js                            2.38 KiB / gzip: 1.09 KiB
.svelte-kit/output/client/ext/pages/todos/index.svelte-9111d728.js                      5.91 KiB / gzip: 2.40 KiB
.svelte-kit/output/client/ext/chunks/singletons-a6a7384f.js                             0.05 KiB / gzip: 0.07 KiB
.svelte-kit/output/client/ext/chunks/vendor-ee294e9e.js                                 14.16 KiB / gzip: 6.04 KiB
.svelte-kit/output/client/ext/assets/pages/about.svelte-bf4528fa.css                    0.11 KiB / gzip: 0.10 KiB
.svelte-kit/output/client/ext/assets/pages/index.svelte-1d45bd0c.css                    1.40 KiB / gzip: 0.50 KiB
.svelte-kit/output/client/ext/assets/pages/todos/index.svelte-784042c1.css              3.70 KiB / gzip: 1.04 KiB
.svelte-kit/output/client/ext/assets/pages/__layout.svelte-8abea7d8.css                 4.95 KiB / gzip: 1.54 KiB
vite v2.8.2 building SSR bundle for production...
✓ 36 modules transformed.
.svelte-kit/output/server/manifest.json                         2.15 KiB
.svelte-kit/output/server/app.js                                63.29 KiB
.svelte-kit/output/server/entries/endpoints/todos/index.js      1.23 KiB
.svelte-kit/output/server/entries/pages/__layout.svelte.js      4.60 KiB
.svelte-kit/output/server/entries/pages/error.svelte.js         0.72 KiB
.svelte-kit/output/server/entries/pages/index.svelte.js         8.07 KiB
.svelte-kit/output/server/entries/pages/about.svelte.js         1.30 KiB
.svelte-kit/output/server/entries/pages/todos/index.svelte.js   5.84 KiB
.svelte-kit/output/server/chunks/index-ee9fdf1a.js              4.24 KiB

Run npm run preview to preview your production build locally.

> Using sveltekit-adapter-browser-extension
> Cannot read properties of undefined (reading 'rimraf')
    at adapt (file:////screener/node_modules/sveltekit-adapter-browser-extension/adapter-browser-extension.mjs:53:10)
    at adapt (file:///screener/node_modules/@sveltejs/kit/dist/chunks/index5.js:886:8)
    at file:///screener/node_modules/@sveltejs/kit/dist/cli.js:1062:11

The environment is Ubuntu on Windows (WSL) and following are the versions:

npm outdated
Package                        Current          Wanted         Latest  Location                             Depended by
@sveltejs/adapter-auto   1.0.0-next.17   1.0.0-next.17  1.0.0-next.23  node_modules/@sveltejs/adapter-auto  screener
@sveltejs/adapter-node   1.0.0-next.68   1.0.0-next.68   1.0.0-next.0  node_modules/@sveltejs/adapter-node  screener
@sveltejs/kit           1.0.0-next.269  1.0.0-next.269   1.0.0-next.1  node_modules/@sveltejs/kit           screener

Note: The @adaptor-node works fine to get the 'build' output but I also get the server/client directories (and I am not sure if the Browser would like them for an addon/extension)

FireMakeThunder commented 2 years ago

It will build with these changes to node_modules\sveltekit-adapter-browser-extension\adapter-browser-extension.mjs:

Replace line 50 with async adapt(utils) { Replace lines 56 with utils.writeStatic(assets) Replace line 57 with utils.writeClient(assets)

What's the reason?

Sveltekit adapters require an adapt function, exported for use during the build process. Before, Sveltekit would pass an object to the adapt function with property utils. Destructuring the object that Sveltekit passes when you build your project, expecting the property utils, no longer works since Sveltekit's has changed their API.

The functions from utils are now at the root of the object passed, so the adapt function should no longer use destructuring. Also, Sveltekit has changed two of those function names, which must be changed.

FireMakeThunder commented 2 years ago

Pull requests and work on other's repositories is new to me. Here is my attempt to fork, branch, and create a pull request with the changes.

Edit: I've removed the fork since there is a better update. https://github.com/FireMakeThunder/sveltekit-adapter-browser-extension/pull/1 See issue https://github.com/antony/sveltekit-adapter-browser-extension/pull/9

antony commented 2 years ago

I believe this has been fixed with the recently opened PR which is now merged. Have a go and see if you have better luck!