Skip to content

. in exports property of CJS file breaks dynamic imports #12622

Closed
@MattIPv4

Description

@MattIPv4

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.11.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

Sentry.init();

Steps to Reproduce

package.json:

{
  "type": "module",
  "dependencies": {
    "@sentry/node": "^8.11.0"
  }
}

index.js:

import * as Sentry from '@sentry/node';

const main = async () => {
  Sentry.init();

  const other = await import(new URL('./other.cjs', import.meta.url));
  console.log(other);
};

main();

other.cjs:

exports['one.two'] = () => console.log('b');

Expected Result

It runs, outputting:

[Module: null prototype] {
  default: { 'one.two': [Function (anonymous)] },
  'one.two': [Function (anonymous)]
}

(this can be reproduced by commenting out the Sentry.init(); line)

Actual Result

It fails on a sytax error:

file://[snip]/other.cjs?iitm=true:21
      let $one.two = _.one.two
              ^

SyntaxError: Unexpected token '.'
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:168:18)
    at callTranslator (node:internal/modules/esm/loader:279:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:285:30)
    at async link (node:internal/modules/esm/module_job:78:21)

Node.js v20.12.2

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions