Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Vite results error in dev mode due to cjs and esm modules usage. #409

Open
itsmnthn opened this issue Aug 28, 2024 · 0 comments
Open

Comments

@itsmnthn
Copy link

itsmnthn commented Aug 28, 2024

Wrote a simple @moar-market/aptos-wallets-vue: A Nuxt layer using wallet-adapter-core for a personal project.

Using this layer to extend it in Nuxt3 project which uses VIte throws these errors for these dependencies, however production build works fine

// latest eventemitter3 does have esm and cjs exports
Uncaught SyntaxError: The requested module '/_nuxt/@fs/Users/name/proj/node_modules/eventemitter3/index.js?v=03fb350f' does not provide an export named 'default' (at index.mjs?v=03fb350f:1:8)

Uncaught SyntaxError: The requested module '/_nuxt/@fs/Users/name/proj/node_modules/tweetnacl/nacl-fast.js?v=327046d2' does not provide an export named 'default' (at index.mjs?v=327046d2:25:8)

Uncaught SyntaxError: The requested module '/_nuxt/@fs/Users/name/proj/node_modules/ed2curve/ed2curve.js?v=0067c408' does not provide an export named 'default' (at index.mjs?v=0067c408:5:8)

// getting same error for buffer
Uncaught SyntaxError: The requested module '/_nuxt/@fs/Users/nickname/moar/oro/node_modules/buffer/index.js?v=a9cd81b9' does not provide an export named 'Buffer' (at index.mjs?v=a9cd81b9:178:10)

// poseidon-lite : also did return this error but resolving at local package manager level worked

I do have solution to prevent this on dev server but I think this should be addressed at adapter-core or ts-sdk level since using vite also more common

Solution
Write alias to resolve correct file in vite config

vite: {
    resolve: {
      alias: {
        eventemitter3: path.resolve(__dirname, 'node_modules/eventemitter3/index.mjs'),
        tweetnacl: path.resolve(__dirname, 'node_modules/tweetnacl/nacl.js'),
        ed2curve: path.resolve(__dirname, 'node_modules/ed2curve/ed2curve.js'),
        buffer: path.resolve(__dirname, 'node_modules/buffer/index.js'),
      },
}

for enforcing new version added these to package.json

{
  "resolutions": {
      "eventemitter3": "^5.0.1",
      "poseidon-lite": "^0.3.0"
    },
}
@itsmnthn itsmnthn changed the title Using Vite results error dev mode due to cjs and esm modules usage. Using Vite results error in dev mode due to cjs and esm modules usage. Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant