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

CommonJS import error #13

Open
herzog0 opened this issue Jul 10, 2023 · 8 comments
Open

CommonJS import error #13

herzog0 opened this issue Jul 10, 2023 · 8 comments

Comments

@herzog0
Copy link

herzog0 commented Jul 10, 2023

I'm trying to use the package in my project, but I'm getting an import error deep inside the @vercel/otel package, so there's nothing I can do about it.
I created the official nextjs example from the docs to ensure this wasn't a problem specific to my project.

$ npx create-next-app --example with-opentelemetry with-opentelemetry-app
$ npm run dev

> dev
> next

- ready started server on 0.0.0.0:3000, url: http://localhost:3000
- warn You have enabled experimental feature (instrumentationHook) in next.config.js.
- warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.

- event compiled client and server successfully in 129 ms (20 modules)
- wait compiling...
- wait compiling /instrumentation (client and server)...
- event compiled client and server successfully in 164 ms (62 modules)
file:///tmp/bla/with-opentelemetry-app/node_modules/@vercel/otel/dist/index.node.js:3
import { Resource } from "@opentelemetry/resources";
         ^^^^^^^^
SyntaxError: Named export 'Resource' not found. The requested module '@opentelemetry/resources' 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 '@opentelemetry/resources';
const { Resource } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5) {
  type: 'SyntaxError'
}

NodeJS version: 18.16.0
npm version: 9.5.1

Update

Apparently, the problem was that I followed these official instructions and there is missing the need to install @opentelemetry/api, which causes the error above.
Following other recipe solved the issue.

@kakadiadarpan
Copy link
Collaborator

@herzog0 Thanks for reporting this issue. It is originating from @opentelemetry/resources package: open-telemetry/opentelemetry-js#3976

For now, we recommend downgrading @opentelemetry/resources to 1.14.0. Once the issue is fixed, you can remove the pinned version from your dependencies.

@mdahiemstra
Copy link

Hi, this is a very recent issue I see :)

I too am having the same issue, even though using @opentelemetry/[email protected]. Also have @opentelemetry/api installed and the problem still persists.

I removed all my node_modules and ran pnpm install again, no luck :(

@kakadiadarpan
Copy link
Collaborator

@mdahiemstra Can you run pnpm list @opentelemetry/resources and share the result please?

@syossan27
Copy link

syossan27 commented Jul 14, 2023

I am in the same situation.
I think this is happening because @opentelemetry/sdk-trace-base v1.15.0 on which @opentelemetry/sdk-trace-node@^1.12.0 specified in @vercel/otel depends which @opentelemetry/sdk-trace-base v1.15.0 depends on.
(I'm a newbie, so sorry if I'm saying something wrong)

Below I have pasted the contents of yarn.lock with excerpts where necessary.

"@vercel/otel@^0.3.0":
  version "0.3.0"
  resolved "https://registry.yarnpkg.com/@vercel/otel/-/otel-0.3.0.tgz#48fcac8fe7e0c4735a586be916930922cba0106c"
  integrity sha512-KgLZjBXmMPKCh9uswY81I6oaVZdH2Eyn4snbx86n20t2LW8iEmjSxzxuviET+lfiIQwWWCiZkC6+SiPXOc7naA==
  dependencies:
    "@opentelemetry/api" "^1.4.1"
    "@opentelemetry/exporter-trace-otlp-grpc" "^0.38.0"
    "@opentelemetry/resources" "^1.12.0"
    "@opentelemetry/sdk-node" "^0.38.0"
    "@opentelemetry/sdk-trace-node" "^1.12.0"
    "@opentelemetry/semantic-conventions" "^1.12.0"

"@opentelemetry/sdk-trace-node@^1.12.0":
  version "1.15.0"
  resolved "https://registry.yarnpkg.com/@opentelemetry/sdk-trace-node/-/sdk-trace-node-1.15.0.tgz#2d49eafb070a6a53e8df7e91dab30ec2370ba310"
  integrity sha512-TKBx9oThZUVKkoGpXhFT/XUgpjq28TWwc6j3JlsL+cJX77DKBnVC+2H+kdVVJHRzyfqDx4LEJJVCwQO3K+cbXA==
  dependencies:
    "@opentelemetry/context-async-hooks" "1.15.0"
    "@opentelemetry/core" "1.15.0"
    "@opentelemetry/propagator-b3" "1.15.0"
    "@opentelemetry/propagator-jaeger" "1.15.0"
    "@opentelemetry/sdk-trace-base" "1.15.0"
    semver "^7.5.1"
    tslib "^2.3.1"

"@opentelemetry/[email protected]":
  version "1.15.0"
  resolved "https://registry.yarnpkg.com/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.15.0.tgz#92340ded8f9fec1aaa63afb40c6e7e01769c2852"
  integrity sha512-udt1c9VHipbZwvCPIQR1VLg25Z4AMR/g0X8KmcInbFruGWQ/lptVPkz3yvWAsGSta5yHNQ3uoPwcyCygGnQ6Lg==
  dependencies:
    "@opentelemetry/core" "1.15.0"
    "@opentelemetry/resources" "1.15.0"
    "@opentelemetry/semantic-conventions" "1.15.0"
    tslib "^2.3.1"

@kakadiadarpan
Copy link
Collaborator

kakadiadarpan commented Jul 14, 2023

For yarn, add the following in your package.json

"resolutions": {
    "@opentelemetry/resources": "<=1.14.0",
    "@opentelemetry/sdk-trace-node": "<=1.14.0",
    "@opentelemetry/semantic-conventions": "<=1.14.0"
  }

For npm or pnpm use "overrides" instead:

"overrides": {
    "@opentelemetry/resources": "<=1.14.0",
    "@opentelemetry/sdk-trace-node": "<=1.14.0",
    "@opentelemetry/semantic-conventions": "<=1.14.0"
  }

This will make sure that all the opentelemetry dependencies that @vercel/otel uses are the versions previous to 0.15.0

cc @mdahiemstra @syossan27

@syossan27
Copy link

syossan27 commented Jul 15, 2023

@kakadiadarpan

Thanks for presenting the code.
I tried it in yarn and it worked fine!

I appreciate your support.

@mdahiemstra
Copy link

For yarn, add the following in your package.json

"resolutions": {
    "@opentelemetry/resources": "<=1.14.0",
    "@opentelemetry/sdk-trace-node": "<=1.14.0",
    "@opentelemetry/semantic-conventions": "<=1.14.0"
  }

For npm or pnpm use "overrides" instead:

"overrides": {
    "@opentelemetry/resources": "<=1.14.0",
    "@opentelemetry/sdk-trace-node": "<=1.14.0",
    "@opentelemetry/semantic-conventions": "<=1.14.0"
  }

This will make sure that all the opentelemetry dependencies that @vercel/otel uses are the versions previous to 0.15.0

cc @mdahiemstra @syossan27

Thanks, i can verify this works. Except the format for pnpm should be:

  "pnpm": {
    "overrides": {
      "@opentelemetry/resources": "<=1.14.0",
      "@opentelemetry/sdk-trace-node": "<=1.14.0",
      "@opentelemetry/semantic-conventions": "<=1.14.0"
    }
  }

Confirmed working!

@mayteio
Copy link

mayteio commented Jul 19, 2023

You can also resolve this by using the transpilePackages config:

transpilePackages: ['@vercel/otel'],

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

5 participants