Skip to content

[Bug:] SyntaxError: Unexpected token 'export' #3720

@averysmithproductions

Description

@averysmithproductions

Describe the Bug

vitest is unable to pass certain tests within our repo, of which use the cmsgov-design-system node package. Please note, not all of our tests fail but these 12 do.

To reproduce

  1. in your terminal, run git clone https://github.cms.gov/PQDC/pqdc-dkan
  2. run git fetch
  3. run git checkout https://github.cms.gov/PQDC/pqdc-dkan/pull/1872
  4. run cd src/frontend
  5. run npm i
  6. run npm run test

Expected behavior

within our repo, npm run test generates the following error message:

SyntaxError: Unexpected token 'export'
Module /Users/asmith/Repos/pqdc-dkan/src/frontend/node_modules/@cmsgov/design-system/dist/react-components/esm/index.js:1 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@cmsgov/design-system" asking them to ship the file in .mjs extension or add "type": "module" in their package.json.

As a temporary workaround you can try to inline the package by updating your config:

// vitest.config.js
export default {
  test: {
    server: {
      deps: {
        inline: [
          "@cmsgov/design-system"
        ]
      }
    }
  }
}

This is causing 12 tests to fail. Screenshot below for context:
Image

Please note, the work-around was unsuccesful.

Severity/Impact

Medium: Product teams can use workaround but still blocker

Desktop Operating System

MacOS 14.6.1

Desktop Browser Name

No response

Desktop Browser Version

No response

Device

No response

Mobile Operating System

No response

Mobile Browser Name

No response

Mobile Browser Version

No response

Additional context

In short, I think https://github.com/CMSgov/design-system/blob/main/package.json needs to have a type: "module" property for vitest to be satisfied.

Please note, our work-around may be to just not make vitest required for deployment.

Codebase/Repository URL

https://github.cms.gov/PQDC/pqdc-dkan

Design System Version

^12.0.0

Existing branch or Pull request on Github

https://github.cms.gov/PQDC/pqdc-dkan/pull/1872

Team Name

PDC

Metadata

Metadata

Assignees

No one assigned

    Labels

    Impacts: CoreImpacts the core DS primarily, changes may occur in other themes as well.Impacts: DocumentationIndicates that this item relates to documentationImpacts: HealthcareImpacts the Healthcare.gov theme directly.Impacts: MedicareImpacts the Medicare theme directly.Status: In JIRAIndicates that this item is also tracked in JiraStatus: Work In ProgressPR's that are not yet ready for reviewdependenciesPull requests that update a dependency filejavascriptPull requests that update javascript code

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions