Skip to content

Vitest issue on @siemens/ix-icons package #95

@windmichael

Description

@windmichael

On our NX repo we have an Angular application, where we use the @siemens/ix-icons library.
Currently we are facing an issue that our Vitest unit tests are not working, because there seems to be a wrong configuration then package.json at the loader folder of the @siemens/ix-icons package.

We receive following error message:

SyntaxError: Unexpected token 'export'
Module C:/Development/siemens-data-cloud-frontend/node_modules/@siemens/ix-icons/loader/index.js:2 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@siemens/ix-icons" 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: [
          "@siemens/ix-icons"
        ]
      }
    }
  }
}

It seams that Vitest expect index.js to be CommonJS, but actually it is ESM.

As far as I found out the reason therefore is, that in the "@siemens/ix-icons/loader/package.json" the property "type": "module" is not set. When adding the property, the test are working.

{
  "name": "ix-icons-loader",
  "private": true,
  "type": "module",
  "typings": "./index.d.ts",
  "module": "./index.js",
  "main": "./index.cjs.js",
  "jsnext:main": "./index.es2017.js",
  "es2015": "./index.es2017.js",
  "es2017": "./index.es2017.js",
  "unpkg": "./cdn.js"
}

When checking your repo I didn't find out where or how this package.json is created. Is it maybe autogenerated?
Would it be possible to fix this?

At the moment I did not find a way how to tell Vitest to treat this package as ESM package. Thus this is blocking us from using Vitest for our unit tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions