denokv icon indicating copy to clipboard operation
denokv copied to clipboard

Problem with the npm package and vite/esbuild

Open StrangeGirlMurph opened this issue 1 year ago • 6 comments

I can't get @deno/kv to work with vite nor esbuild.

With vite/rollup I get:

[commonjs--resolver] Unexpected character '' (Note that you need plugins to import files that are not JavaScript)
file: /home/murphy/.../obsidian-memorize/node_modules/@deno/kv/esm/_napi_index.cjs:1:0
1: ELF>��@ �/@8 @����...
   ^
2: ���_:��|`�EoS>...
3: l�...

Which appears to be related to: https://github.com/vitejs/vite/issues/3304 and https://github.com/vitejs/vite/issues/12246. I don't know much else though. I am not very familiar with bundlers and all the cjs vs esm details. After all I tried I do think it's a thing about this package though.

With esbuild I get some other errors. I am mostly interested in getting it with vite to work though
✘ [ERROR] Top-level await is currently not supported with the "cjs" output format

    node_modules/@deno/kv/esm/napi_based.js:34:31:
      34 │ const DEFAULT_NAPI_INTERFACE = await import('./_napi_index.cjs');
         ╵                                ~~~~~

✘ [ERROR] No loader is configured for ".node" files: node_modules/@deno/kv-linux-x64-gnu/deno-kv-napi.linux-x64-gnu.node

    node_modules/@deno/kv/esm/_napi_index.cjs:92:38:
      92 │               nativeBinding = require('@deno/kv-linux-x64-gnu')
         ╵                                       ~~~~~~~~~~~~~~~~~~~~~~~~

A bit of context: I am writing an obsidian.md plugin. So all code gets bundled into a single main.js which then gets run by obsidian (an electron app).

StrangeGirlMurph avatar Jan 06 '24 11:01 StrangeGirlMurph

I am facing the same problem with node + vite. I have changed the vite config file but to no avail. Have you solved this problem? Please let me know if you have any findings.

vite.config.ts

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';

export default defineConfig({
	plugins: [sveltekit()],
	optimizeDeps: { exclude: ["@deno/kv-win32-x64-msvc", "kv-win32-x64-msvc"] },
});

npm run build

vite v5.0.12 building SSR bundle for production...
✓ 854 modules transformed.
vite v5.0.12 building for production...
✓ 842 modules transformed.
.svelte-kit/output/client/_app/version.json                              0.03 kB │ gzip:  0.05 kB
.svelte-kit/output/client/.vite/manifest.json                            3.83 kB │ gzip:  0.59 kB
.svelte-kit/output/client/_app/immutable/assets/0.EVAk5Zfp.css         127.24 kB │ gzip: 17.46 kB
.svelte-kit/output/client/_app/immutable/entry/start.zPFxh-aL.js         0.07 kB │ gzip:  0.08 kB
.svelte-kit/output/client/_app/immutable/chunks/index.7ZXhex3t.js        0.45 kB │ gzip:  0.32 kB
.svelte-kit/output/client/_app/immutable/nodes/0.JZm_CXwy.js             0.60 kB │ gzip:  0.39 kB
.svelte-kit/output/client/_app/immutable/nodes/1.QZgo66aJ.js             1.02 kB │ gzip:  0.59 kB
.svelte-kit/output/client/_app/immutable/nodes/3.IwiuJ8qN.js             3.25 kB │ gzip:  1.34 kB
.svelte-kit/output/client/_app/immutable/chunks/List.dRyasWuV.js         3.37 kB │ gzip:  1.55 kB
.svelte-kit/output/client/_app/immutable/chunks/FaqItem.twKDQ7An.js      4.60 kB │ gzip:  2.06 kB
.svelte-kit/output/client/_app/immutable/chunks/index.6wC7yepp.js        4.71 kB │ gzip:  2.41 kB
.svelte-kit/output/client/_app/immutable/entry/app.tAiWsni9.js           6.40 kB │ gzip:  2.56 kB
.svelte-kit/output/client/_app/immutable/chunks/scheduler.et4AooKP.js    8.93 kB │ gzip:  3.52 kB
.svelte-kit/output/client/_app/immutable/nodes/4.aZPorD8H.js            10.25 kB │ gzip:  3.20 kB
.svelte-kit/output/client/_app/immutable/chunks/Footer.I3y52y5z.js      25.73 kB │ gzip:  8.65 kB
.svelte-kit/output/client/_app/immutable/chunks/entry.c4Q570SV.js       26.52 kB │ gzip: 10.50 kB
.svelte-kit/output/client/_app/immutable/nodes/2.7fM3a-F_.js           113.76 kB │ gzip: 31.11 kB
✓ built in 6.35s
.svelte-kit/output/server/.vite/manifest.json                                   3.18 kB
.svelte-kit/output/server/_app/immutable/assets/_layout.zXinSzkU.css          127.16 kB
.svelte-kit/output/server/entries/pages/_layout.svelte.js                       0.24 kB
.svelte-kit/output/server/entries/pages/_page.server.ts.js                      0.30 kB
.svelte-kit/output/server/internal.js                                           0.31 kB
.svelte-kit/output/server/chunks/private.js                                     0.32 kB
.svelte-kit/output/server/entries/endpoints/api/server/players/_server.ts.js    0.78 kB
.svelte-kit/output/server/entries/fallbacks/error.svelte.js                     1.18 kB
.svelte-kit/output/server/chunks/index2.js                                      1.33 kB
.svelte-kit/output/server/entries/pages/privacy-policy/_page.svelte.js          1.67 kB
.svelte-kit/output/server/entries/endpoints/api/server/player/_server.ts.js     1.68 kB
.svelte-kit/output/server/chunks/List.js                                        2.24 kB
.svelte-kit/output/server/chunks/index.js                                       2.26 kB
.svelte-kit/output/server/chunks/FaqItem.js                                     3.08 kB
.svelte-kit/output/server/chunks/Footer.js                                      4.76 kB
.svelte-kit/output/server/chunks/exports.js                                     5.96 kB
.svelte-kit/output/server/chunks/internal.js                                    6.03 kB
.svelte-kit/output/server/entries/pages/support/_page.svelte.js                 6.05 kB
.svelte-kit/output/server/chunks/ssr.js                                         8.27 kB
.svelte-kit/output/server/entries/pages/_page.svelte.js                        71.55 kB
.svelte-kit/output/server/index.js                                             90.17 kB

Run npm run preview to preview your production build locally.

> Using deno-deploy-adapter
X [ERROR] No loader is configured for ".node" files: node_modules/@deno/kv-win32-x64-msvc/deno-kv-napi.win32-x64-msvc.node

    node_modules/@deno/kv/esm/_napi_index.cjs:41:36:
      41 │             nativeBinding = require('@deno/kv-win32-x64-msvc')
         ╵                                     ~~~~~~~~~~~~~~~~~~~~~~~~~

Error: Build failed with 1 error:
node_modules/@deno/kv/esm/_napi_index.cjs:41:36: ERROR: No loader is configured for ".node" files: node_modules/@deno/kv-win32-x64-msvc/deno-kv-napi.win32-x64-msvc.node
    at failureErrorWithLog (D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:1651:15)
    at D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:1059:25
    at D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:1004:52
    at buildResponseToResult (D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:1057:7)
    at D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:1086:16
    at responseCallbacks.<computed> (D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:704:9)
    at handleIncomingPacket (D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:764:9)
    at Socket.readFromStdout (D:\workspace\svelte\palworld-player-sav-search\node_modules\esbuild\lib\main.js:680:7)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:324:12) {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

rinjugatla avatar Jan 27 '24 16:01 rinjugatla

Sadly I haven't solved this. I also haven't really tried. Creating this issue was my last resort. Everything I tried before didn't work. Sadly none of the devs seem to pay attention or care about this.

StrangeGirlMurph avatar Jan 27 '24 19:01 StrangeGirlMurph

Thank you for contacting us. I am very sad because my app is complete but I can't deploy it. I will contact you again when there is progress.

rinjugatla avatar Jan 28 '24 03:01 rinjugatla

related: https://github.com/evanw/esbuild/issues/1051

marvinhagemeister avatar Feb 01 '24 10:02 marvinhagemeister

Thank you very much. I have tried various settings for the vite at the end of the related link, but could not resolve the issue. If you have a vite setting that has solved the problem, I would be glad to have the code.

rinjugatla avatar Feb 03 '24 07:02 rinjugatla

@johnspurlock-skymethod can you help us with this?

StrangeGirlMurph avatar Mar 05 '24 19:03 StrangeGirlMurph