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

Error: The requested module 'vue' does not provide an export named 'computed' #12490

Closed
3 tasks done
Tracked by #12485
vedmant opened this issue Jun 14, 2024 · 21 comments
Closed
3 tasks done
Tracked by #12485
Assignees
Labels

Comments

@vedmant
Copy link

vedmant commented Jun 14, 2024

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.9.2

Framework Version

Nuxt Version: 3.12.1

Link to Sentry event

No response

SDK Setup


  • Operating System: Darwin
  • Node Version: v20.12.2
  • Nuxt Version: 3.12.1
  • CLI Version: 3.12.0
  • Nitro Version: 2.9.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

// server/plugins/sentry.js
import { defineNitroPlugin } from 'nitropack/dist/runtime/plugin'
import * as Sentry from '@sentry/node'
import { useRuntimeConfig } from '#imports'

export default defineNitroPlugin(() => {
  const { public: { sentry } } = useRuntimeConfig()

  // If no sentry DSN set, ignore and warn in the console
  if (!sentry.dsn) {
    console.warn('Sentry DSN not set, skipping Sentry initialization')
  }

  // Initialize Sentry
  Sentry.init({
    dsn: sentry.dsn,
    environment: sentry.environment,
  })
})

Steps to Reproduce

Setup Nuxt project with server plugin
Run in dev mode (it works ok for build)

// server/plugins/sentry.js
import { defineNitroPlugin } from 'nitropack/dist/runtime/plugin'
import * as Sentry from '@sentry/node'
import { useRuntimeConfig } from '#imports'

export default defineNitroPlugin(() => {
  const { public: { sentry } } = useRuntimeConfig()

  // If no sentry DSN set, ignore and warn in the console
  if (!sentry.dsn) {
    console.warn('Sentry DSN not set, skipping Sentry initialization')
  }

  // Initialize Sentry
  Sentry.init({
    dsn: sentry.dsn,
    environment: sentry.environment,
  })
})

Expected Result

No error

Actual Result

 ERROR  [nuxt] [request error] [unhandled] [500] The requested module 'vue' does not provide an export named 'computed'
  at ModuleJob._instantiate (node:internal/modules/esm/module_job:134:21)  
  at async ModuleJob.run (node:internal/modules/esm/module_job:217:5)  
  at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)  
  at async ViteNodeRunner.interopedImport (./node_modules/vite-node/dist/client.mjs:384:28)  
  at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:253:24)  
  at async ViteNodeRunner.cachedRequest (./node_modules/vite-node/dist/client.mjs:189:14)  
  at async ViteNodeRunner.dependencyRequest (./node_modules/vite-node/dist/client.mjs:233:12)  
  at async ./virtual:nuxt:/Users/me/app-site/.nuxt/vue-router-stub.mjs:1:31  
  at async ViteNodeRunner.runModule (./node_modules/vite-node/dist/client.mjs:362:5)  
  at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:346:5) (repeated 2 times)

@github-actions github-actions bot added the Package: node Issues related to the Sentry Node SDK label Jun 14, 2024
@AbhiPrasad
Copy link
Member

@vedmant if you set globalThis._sentryEsmLoaderHookRegistered = true; before you call Sentry.init does the error still happen?

You are also late initializing the SDK, which means you need to follow these docs: https://docs.sentry.io/platforms/javascript/guides/node/install/late-initializtion/

@DavidDeSloovere
Copy link

Same error for me. Using Sentry.init triggers the error.
Works on 7.117.0 without issue.

Adding globalThis._sentryEsmLoaderHookRegistered = true; before Sentry.init makes the error go away.

I'm assuming proper 'Late Initialization' is beter.
I don't know how to do the 'Late Initialization' with Nuxt (Nitro in this case). Anyone here know how to do it? Should we check this in the Nitro repo?

@AbhiPrasad
Copy link
Member

So this means it's an issue with ESM. I'll add it to our current list of items, being tracked here: #12485

globalThis._sentryEsmLoaderHookRegistered = true disable all automatic instrumentation for performance monitoring, but you should be able to use errors like usual!

We never had real ESM support before with 7.x.x, so only with v8 do we encounter these issues - ESM has it's problems 😓.

@AbhiPrasad
Copy link
Member

I don't know how to do the 'Late Initialization' with Nuxt (Nitro in this case). Anyone here know how to do it? Should we check this in the Nitro repo?

When you run nuxt build you'll get an entry point that you can run node XXX on. This is documented here.

When you run node XXX, you just need to add the required command line options as per the docs in late initialization!

@timfish
Copy link
Collaborator

timfish commented Jun 15, 2024

This should hopefully have been fixed by the numerous PRs recently merged at import-in-the-middle.

While we wait for this to be released, there is a patch available that combines all the fixes. If anyone can confirm this patch fixes this issue that would be super helpful!

@DavidDeSloovere
Copy link

I can confirm that the newer versions don't require the workaround anymore. 👌
This issue can be closed if you ask me.

@sethbrasile
Copy link

sethbrasile commented Jun 27, 2024

I'm running into this issue in Nuxt, using @sentry/node 8.13 and @sentry/profiling-node 8.13.

In my case, it doesn't throw the same error as OP, instead it just hangs indefinitely without throwing any error.

Any release >=8.0.0 presents this behavior.

The stated workaround does work.

@AbhiPrasad
Copy link
Member

@sethbrasile could you share how you are initializing the SDK?

We have a Nuxt SDK being actively built - please keep an eye on that! #9095

See #12681, that's a PR that shows how to initialize Sentry in the client. You might need to use a similar strategy.

@bubooon
Copy link

bubooon commented Jun 29, 2024

Hey folks, I am facing the same issue using nuxt but with some notes.

  1. The huck from above (globalThis._sentryEsmLoaderHookRegistered = true) helps when build mode is development
  2. The patch from above couldn't be applied because as I understood it was already released in import-in-the-middle@^1.8.1.
    But the question then is why I still need to apply that huck to make app working?...
  3. No errors or warnings with the huck applied when build mode is production BUT no errors at all are propagated to sentry.io dashboard, so in other words it doesn't work in production when at the same time VUE plugin for client side works without issues.

Let know if you need more information to help you fix that, thanks!

My env:

  • All in docker node:20.9.0
  • I use exat versions in my package.json:
    "@sentry/node": "8.13.0",
    "@sentry/profiling-node": "8.13.0",
    "@sentry/vite-plugin": "2.20.1",
    "@sentry/vue": "8.13.0",
  • import-in-the-middle in my yarn.lock file:
[email protected]:
  version "1.4.2"
  resolved "https://registry.yarnpkg.com/import-in-the-middle/-/import-in-the-middle-1.4.2.tgz#2a266676e3495e72c04bbaa5ec14756ba168391b"
  integrity sha512-9WOz1Yh/cvO/p69sxRmhyQwrIGGSp7EIdcb+fFNVi7CzQGQB8U1/1XrKVSbEd/GNOAeM0peJtmi7+qphe7NvAw==
  dependencies:
    acorn "^8.8.2"
    acorn-import-assertions "^1.9.0"
    cjs-module-lexer "^1.2.2"
    module-details-from-path "^1.0.3"

import-in-the-middle@^1.8.1:
  version "1.8.1"
  resolved "https://registry.yarnpkg.com/import-in-the-middle/-/import-in-the-middle-1.8.1.tgz#8b51c2cc631b64e53e958d7048d2d9463ce628f8"
  integrity sha512-yhRwoHtiLGvmSozNOALgjRPFI6uYsds60EoMqqnXyyv+JOIW/BrrLejuTGBt+bq0T5tLzOHrN0T7xYTm4Qt/ng==
  dependencies:
    acorn "^8.8.2"
    acorn-import-attributes "^1.9.5"
    cjs-module-lexer "^1.2.2"
    module-details-from-path "^1.0.3"
  • Error log when the hack is not applied:
[0] error occured The requested module 'vue' does not provide an export named 'computed'
2024-06-29T09:21:29.842333094Z [0] 
2024-06-29T09:21:29.842336090Z [0]   import { getCurrentInstance, inject, onUnmounted, onDeactivated, onActivated, computed, unref, watchEffect, defineComponent, reactive, h, provide, ref, watch, shallowRef, shallowReactive, nextTick } from 'vue';
2024-06-29T09:21:29.842337828Z [0]   ^^^^^^^^
2024-06-29T09:21:29.842339123Z [0]   SyntaxError: The requested module 'vue' does not provide an export named 'computed'
2024-06-29T09:21:29.842340460Z [0]   at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
2024-06-29T09:21:29.842341866Z [0]   at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
2024-06-29T09:21:29.842343093Z [0]   at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
2024-06-29T09:21:29.842344353Z [0]   at async ViteNodeRunner.interopedImport (node_modules/vite-node/dist/client.mjs:383:28)
2024-06-29T09:21:29.842353235Z [0]   at async ViteNodeRunner.directRequest (node_modules/vite-node/dist/client.mjs:253:24)
2024-06-29T09:21:29.842354965Z [0]   at async ViteNodeRunner.cachedRequest (node_modules/vite-node/dist/client.mjs:189:14)
2024-06-29T09:21:29.842356253Z [0]   at async ViteNodeRunner.dependencyRequest (node_modules/vite-node/dist/client.mjs:233:12)
2024-06-29T09:21:29.842357491Z [0]   at async virtual:nuxt:/usr/src/frontend/app/.nuxt/vue-router-stub.mjs:1:31
2024-06-29T09:21:29.842358866Z [0]   at async ViteNodeRunner.runModule (node_modules/vite-node/dist/client.mjs:362:5)
2024-06-29T09:21:29.842360180Z [0]   at async ViteNodeRunner.directRequest (node_modules/vite-node/dist/client.mjs:346:5)
  • My plugin for nitro:
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import { H3Error } from 'h3';

export default defineNitroPlugin(nitroApp => {
  const {
    public: { sentry },
  } = useRuntimeConfig();

  if (!sentry.dsn) {
    // eslint-disable-next-line no-console
    console.warn('Sentry DSN not set, skipping Sentry initialization');
    return;
  }

  // TODO remove after fix is released https://github.com/getsentry/sentry-javascript/issues/12485
  // @ts-ignore
  // eslint-disable-next-line no-underscore-dangle
  globalThis._sentryEsmLoaderHookRegistered = true;

  Sentry.init({
    dsn: sentry.dsn,
    environment: sentry.environment,
    release: sentry.release,
    integrations: [nodeProfilingIntegration()],
    tracesSampleRate: 1.0,
    profilesSampleRate: 1.0,
  });

  nitroApp.hooks.hook('error', error => {
    if (error instanceof H3Error) {
      if (error.statusCode === 404) {
        return;
      }
    }

    Sentry.captureException(error);
  });

  nitroApp.hooks.hook('request', event => {
    // eslint-disable-next-line no-param-reassign
    event.context.$sentry = Sentry;
  });

  nitroApp.hooks.hookOnce('close', async () => {
    await Sentry.close(2000);
  });
});

@timfish
Copy link
Collaborator

timfish commented Jun 29, 2024

Hey @bubooon, I'm looking into your issue but I'm struggling to reproduce it since nitro is new to me! Do you have a minimal reproduction I can run?

This should probably go in a new issue as it looks like this is a new issue!

@bubooon
Copy link

bubooon commented Jun 29, 2024

Hey @timfish
You can try to bootstrap clean nuxt 3 project, then add plugin I provided to ./server/plugins dirrectory (create the directory if needed and add packages)
in nuxt.config.ts add:

export default defineNuxtConfig({
  ssr: true,
  debug: false,
  nitro: {
    output: {
      dir: '/path/to/.output',
    },
  },
})

add ./middleware/0.test.global.ts

export default defineNuxtRouteMiddleware(async (to, _) => {
  if (process.server) {
    throw new Error('test');
  }
});

then run:

nuxi prepare .
nuxt build
NODE_TLS_REJECT_UNAUTHORIZED="0" node /path/to/.output/server/index.mjs

Also usefull to look this article

Let me know if this didn't help, I should be able to prepare and upload example somewhere on Monday

@timfish
Copy link
Collaborator

timfish commented Jun 29, 2024

I followed the above instructions but don't get any errors at build or runtime. If I set debug: true in the Sentry options I see the debug output so Sentry is getting started.

Have you tried removing yarn.lock, installing and trying again?

@bubooon
Copy link

bubooon commented Jun 29, 2024

No errors is expected behavior but does it send server errors when they occur to Sentry dashboard?

@timfish
Copy link
Collaborator

timfish commented Jun 29, 2024

No errors is expected behavior

Above you said:

Error log when the hack is not applied

[0] error occured The requested module 'vue' does not provide an export named 'computed'
2024-06-29T09:21:29.842333094Z [0] 
2024-06-29T09:21:29.842336090Z [0]   import { getCurrentInstance, inject, onUnmounted, onDeactivated, onActivated, computed, unref, watchEffect, defineComponent, reactive, h, provide, ref, watch, shallowRef, shallowReactive, nextTick } from 'vue';
2024-06-29T09:21:29.842337828Z [0]   ^^^^^^^^
2024-06-29T09:21:29.842339123Z [0]   SyntaxError: The requested module 'vue' does not provide an export named 'computed'

I don't get any error logged with the hack is not applied and no errors are sent to Sentry.

If you open a fresh issue with a reproduction and details of what you're expecting and what's happening instead, I'll be happy to take a look!

@bubooon
Copy link

bubooon commented Jun 29, 2024

Ok, I will. But just to clarify, the issue is that the sentry-javascript doesn't send error reports to Sentry servers with that huck applied when u built Nuxt in production mode.

@samasarin
Copy link

Putting "globalThis._sentryEsmLoaderHookRegistered = true;" befor Sentry init fixed my issue for now.

@minht11
Copy link

minht11 commented Jul 4, 2024

Experiencing the same error while using @sentry/astro, upgraded from 7.98.0 and any >=8.0.0 produces the same error. Using latest version and still experiencing this issue, so not I am not sure it is fixed.

@bubooon
Copy link

bubooon commented Jul 5, 2024

Hey @timfish
I have some updates regarding my problems

  1. Forget what I said regarding sending events to Sentry servers doesn't work, it actiually works. I haven't realised that if I archive issue all new arrors will still fall into that archived issue and never unarchive it anymore, which works basically as "ignore" functionality in Sentry issues dashboard.
  2. I prepared the project which should allow you reproduce the issue with The requested module 'vue' does not provide an export named 'computed' but supriselly for me the issue occures but now error message is completelly diffirent there, but I believe it has a relation to the same problem. Please take a look if you can reproduce it and let me know if I need maybe open another issue request for that?

@AbhiPrasad
Copy link
Member

@bubooon mind opening a new GH issue? That will make sure we can dive into your reproduction case without involving everyone else on this thread.

With the newest release of import-in-the-middle v1.9.0 this should be fixed, so new issues + repro are greatly appreciated is you are still encountering issues.

If you upgrade to a fresh install of the latest version of the Node SDK it should use [email protected] by default.

@TimGuendel
Copy link

Same error here. I added nodeProfilingIntegration to a nitro plugin (in a Nuxt3 project) and I am getting this error when starting the server.

@AbhiPrasad
Copy link
Member

@TimGuendel could you open a new GH issue and fill out all the details about your app? Ideally attaching a reproduction as well.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

9 participants