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

Inconsistent CommonJS import in development and production #14631

Closed
andresespinosapc opened this issue Aug 17, 2022 · 4 comments
Closed

Inconsistent CommonJS import in development and production #14631

andresespinosapc opened this issue Aug 17, 2022 · 4 comments

Comments

@andresespinosapc
Copy link

andresespinosapc commented Aug 17, 2022

Environment

  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0-rc.8
  • Package Manager: npm@7.17.0
  • Builder: vite
  • User Config: vite
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-c5nszx?file=package.json

First run npm run dev and you'll not get the error, then run npm run build && npm start and you'll get it.

Describe the bug

When importing from a CommonJS module with this syntax: import { method } from 'module';, it works fine in development but it breaks on production.

Additional context

No response

Logs

[nuxt] [request error] [unhandled] [500] Named export 'captureException' not found. The requested module '@sentry/vue' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@sentry/vue';
const { captureException } = pkg;

  at async eval (./.output/server/chunks/handlers/renderer.mjs:11115:24)  
  at async eval (./.output/server/chunks/handlers/renderer.mjs:11169:64)  
  at async eval (./.output/server/chunks/handlers/renderer.mjs:33:22)  
  at async eval (./.output/server/node_modules/h3/dist/index.mjs:571:19)
@huang-julien
Copy link
Member

HI ! did you try to transpile it ?

import { defineNuxtConfig } from 'nuxt';

// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
  build: {
    transpile: ['@sentry/vue'],
  },
});
````

@andresespinosapc
Copy link
Author

@huang-julien I just tried and it doesn't throw the error if I transpile it. Anyway, I think it shouldn't work differently in development and production, or the transpile should be automatic.

@vaban-ru
Copy link

Same thing, i have error in dev mode, but it is work fine in production mode with transpile config option

@danielroe
Copy link
Member

let's track in #14790.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Sep 15, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants