matrix-org / matrix-js-sdk

Matrix Client-Server SDK for JavaScript
Apache License 2.0
1.62k stars 590 forks source link

Failed to resolve entry for package "matrix-js-sdk" #3013

Closed kfiven closed 1 year ago

kfiven commented 1 year ago

When trying to start a dev server or build app, my build system reports:

[commonjs--resolver] Failed to resolve entry for package "matrix-js-sdk". The package may have incorrect main/module/exports specified in its package.json.
error during build:
Error: Failed to resolve entry for package "matrix-js-sdk". The package may have incorrect main/module/exports specified in its package.json.
    at packageEntryFailure (file:///home/runner/work/cinny/cinny/node_modules/vite/dist/node/chunks/dep-2285ba4f.js:22938:11)
    at resolvePackageEntry (file:///home/runner/work/cinny/cinny/node_modules/vite/dist/node/chunks/dep-2285ba4f.js:22935:5)
    at tryNodeResolve (file:///home/runner/work/cinny/cinny/node_modules/vite/dist/node/chunks/dep-2285ba4f.js:22671:[20](https://github.com/cinnyapp/cinny/actions/runs/3783229035/jobs/6431607704#step:5:21))
    at Object.resolveId (file:///home/runner/work/cinny/cinny/node_modules/vite/dist/node/chunks/dep-2285ba4f.js:22435:28)
    at file:///home/runner/work/cinny/cinny/node_modules/rollup/dist/es/shared/rollup.js:23451:40
Error: Process completed with exit code 1.

Started happening with sdk version 23.0.0 node: v18.12.1 yarn: 1.22.19 npm: 8.19.2

ankit-pn commented 1 year ago

Can you specify in more detail how to reproduce this issue? because this is working fine for me!

kfiven commented 1 year ago

Clone https://github.com/cinnyapp/cinny/tree/dependabot/npm_and_yarn/matrix-js-sdk-23.0.0 and then

npm ci

npm start
davidisaaclee commented 1 year ago

@kfiven I think this could be related to https://github.com/matrix-org/matrix-js-sdk/issues/3015 – specifically, that matrix-js-sdk's package.json#browser is set to ./lib/browser-index.ts, which afaict is not an existent file.

I have steps in that issue for how I fixed this for create-react-app / Webpack 5; maybe they'd work for you as well?

MTRNord commented 1 year ago

This seems to also break vitejs:

✘ [ERROR] [plugin vite:dep-scan] Failed to resolve entry for package "matrix-js-sdk". The package may have incorrect main/module/exports specified in its package.json.

    node_modules/esbuild/lib/main.js:1357:21:
      1357 │         let result = await callback({
           ╵                      ^

    at packageEntryFailure (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:21837:11)
    at resolvePackageEntry (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:21834:5)
    at tryNodeResolve (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:21572:20)
    at Context.resolveId (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:21336:28)
    at Object.resolveId (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41433:46)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async resolve (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41661:26)
    at async file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41835:34
    at async requestCallbacks.on-resolve (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:1357:22)
    at async handleRequest (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:723:13)

  This error came from the "onResolve" callback registered here:

    node_modules/esbuild/lib/main.js:1281:20:
      1281 │       let promise = setup({
           ╵                     ^

    at setup (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41825:19)
    at handlePlugins (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:1281:21)
    at buildOrServeImpl (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:970:5)
    at Object.buildOrServe (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:776:5)
    at /var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:2117:17
    at new Promise (<anonymous>)
    at Object.build (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:2116:14)
    at build (/var/home/marcel/projects/matrix-art/node_modules/esbuild/lib/main.js:1963:51)
    at scanImports (file:///var/home/marcel/projects/matrix-art/node_modules/vite/dist/node/chunks/dep-5e7f419b.js:41606:11)

  The plugin "vite:dep-scan" was triggered by this import

    src/matrix/client.ts:15:7:
      15 │ } from 'matrix-js-sdk';
         ╵        ~~~~~~~~~~~~~~~

Build failed with 1 error:
node_modules/esbuild/lib/main.js:1357:21: ERROR: [plugin: vite:dep-scan] Failed to resolve entry for package "matrix-js-sdk". The package may have incorrect main/module/exports specified in its package.json.