ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

[SF][CheckboxTemplate/JSX-runtime]: Cannot find module '@ui5/webcomponents-base/jsx-runtime' error on version 2.6.0

Open Ankitadoshi opened this issue 1 year ago • 16 comments

Bug Description

When we upgrade webcomponents to 2.6.X version, and run the build or unit test cases we are getting error as below: This is happening for multiple components that uses List or table with Multiselect selection mode. This is a high priority issue for us since we need 2.6.x version to implement the drag and drop feature for our project.

Component Versions: "@ui5/webcomponents": "^2.6.0", "@ui5/webcomponents-compat": "~2.6.0", "@ui5/webcomponents-base": "^2.6.0", "@ui5/webcomponents-fiori": "^2.6.0", "@ui5/webcomponents-icons": "^2.4.0", "@ui5/webcomponents-localization": "~2.4.0", "@ui5/webcomponents-react": "^2.6.0", "@ui5/webcomponents-react-compat": "^2.6.0",

While running test cases: Cannot find module '@ui5/webcomponents-base/jsx-runtime' from 'node_modules/@ui5/webcomponents/dist/CheckBoxTemplate.js' Require stack: node_modules/@ui5/webcomponents/dist/CheckBoxTemplate.js node_modules/@ui5/webcomponents/dist/CheckBox.js node_modules/@ui5/webcomponents-react/dist/webComponents/CheckBox/index.js node_modules/@ui5/webcomponents-react/dist/components/AnalyticalTable/pluginHooks/useRowDisableSelection.js node_modules/@ui5/webcomponents-react/dist/components/AnalyticalTable/pluginHooks/AnalyticalTableHooks.js node_modules/@ui5/webcomponents-react/dist/index.js src/utils/pickListFilterUtils.js src/store/middleware/filtersSlice.js src/Components/Filters/Filters.js src/Components/Filters/Filters.test.js

While building: Failed to parse source map from '/Users/I523602/Desktop/dev/src/recruiting-applicationlist/node_modules/@ui5/webcomponents-base/dist/prod/thirdparty/preact/jsxRuntime.module.js.map' file: Error: ENOENT: no such file or directory, open '/Users/I523602/Desktop/dev/src/recruiting-applicationlist/node_modules/@ui5/webcomponents-base/dist/prod/thirdparty/preact/jsxRuntime.module.js.map'

Can you please let us know on how to resolve these errors?

Affected Component

SF

Expected Behaviour

The test cases and the build should should pass without any issues

Isolated Example

No response

Steps to Reproduce

  1. Upgrade to web components 2.6.0
  2. Run npm install
  3. Run unit test cases or buils ...

Log Output, Stack Trace or Screenshots

No response

Priority

High

UI5 Web Components Version

2.6.0

Browser

Chrome

Operating System

No response

Additional Context

No response

Organization

No response

Declaration

  • [x] I’m not disclosing any internal or sensitive information.

Ankitadoshi avatar Feb 03 '25 04:02 Ankitadoshi

The error when building (missing .js.map) is fixed with https://github.com/SAP/ui5-webcomponents/pull/10596 and available in the latest RC https://github.com/SAP/ui5-webcomponents/releases/tag/v2.7.0-rc.2 2.7 will be released this week.

The error in the tests is somewhat different, can't really tell without further info. Can you try if 2.7.0-rc.2 fixes both errors and let me know?

pskelin avatar Feb 03 '25 05:02 pskelin

Hi @pskelin Yes post upgrading to 2.7.0, the issue with the build (missing .js.map) is resolved.

But our test cases are still failing. Seems like there are two issues:

  1. As per my analysis this seems to be a path problem for jsx-runtime file. We see that multiple JS files like ***template.js are present for various components in the webcomponents/dist folder once we do npm install These template files all have import for jsx-runtime. For example in CheckboxTemplate.js first line. import { jsx as _jsx, jsxs as _jsxs } from "@ui5/webcomponents-base/jsx-runtime"; And if i check the @ui5/webcomponents-base package, the jsx-runtime is present in the dist folder so i feel that these import needs to be changed from
import { jsx as _jsx, jsxs as _jsxs } from "@ui5/webcomponents-base/jsx-runtime"; 
to 
import { jsx as _jsx, jsxs as _jsxs } from "@ui5/webcomponents-base/dist/jsx-runtime";
  1. Another issue is from the React Wrapper(ui5-webcomponents-react) as I can see the imports are not correctly added there as well https://github.com/SAP/ui5-webcomponents-react/blob/d68bd2c7ddc6848dc81655742f3fdbb622078dd9/packages/base/src/utils/index.ts Here as well the path does not have dist/
import { getEffectiveScopingSuffixForTag } from '@ui5/webcomponents-base/CustomElementsScope.js';
But the actual file is present inside dist folder so the import path should be
import { getEffectiveScopingSuffixForTag } from '@ui5/webcomponents-base/dist/CustomElementsScope.js';

Not sure if we are missing any configurations here. Please let me know if more information is needed

Ankitadoshi avatar Feb 04 '25 10:02 Ankitadoshi

In the @ui5/webcomponents-base package.json we have this configuration that is supposed to handle the import to "@ui5/webcomponents-base/jsx-runtime":


"exports": {
    "./jsx-runtime": "./dist/jsx-runtime.js",
    "./jsx-dev-runtime": "./dist/jsx-dev-runtime.js",
     ...

And for the second:

import { getEffectiveScopingSuffixForTag } from '@ui5/webcomponents-base/CustomElementsScope.js';

we do reexport of a lot of modules ( including CustomElementsScope) via this index.js file.

I suggest we get in contact offline to get the project running..

ilhan007 avatar Feb 04 '25 11:02 ilhan007

Hi @ilhan007 Please let me know if there is any updates here. This is high priority for us since without this upgrade, We cannot take up drag and drop feature which is must have for our release

Thanks, Ankita

Ankitadoshi avatar Feb 07 '25 03:02 Ankitadoshi

Update 1

Failure 1:

Cannot find module '@ui5/webcomponents-base/CustomElementsScope.js' from 'node_modules/@ui5/webcomponents-react-base/dist/utils/index.js

Solution: This is fixed and released with @ui5/webcomponents-react 2.7.1. I have updated your project locally to test the fix and the this failure stopped.


Failure 2:

Cannot find module '@ui5/webcomponents-base/jsx-runtime' from 'node_modules/@ui5/webcomponents/dist/CheckBoxTemplate.js'

Solution: Seems the reexports are not working fine with jest (all issues happen only in tests), so I have configured this mapping in the package.json under the "jest":

"moduleNameMapper": {
      "^@ui5/webcomponents-base/jsx-runtime$": "<rootDir>/node_modules/@ui5/webcomponents-base/dist/jsx-runtime.js"
}

Failure 3:

TypeError: Cannot read properties of undefined (reading 'states') at Button._setBadgeOverlayStyle (node_modules/@ui5/webcomponents/src/Button.ts:379:20)

Solution: This is a known problem, jest does not support a lot of browser native APIs, and recently we added code to the Button that uses ElementInternals API (which is standard browser API), but not supported in jest. However, to make jest users happy we already merged this fix that provides a shim for the missing native API in jest.

ilhan007 avatar Feb 07 '25 11:02 ilhan007

Update 2:

We have released 2.7.1 for all packages on the public npm (including the aforementioned ElementInternals shim for jest/jsdom env), but not available on the internal registry https://int.repositories.cloud.sap/artifactory/api/

Once available:

  • Update your package.json, clean node_modules, and install 2.7.1 for all @ui5/* packages (see the screenshot)
  • Add the moduleNameMapper setting in your package.json under jest (see the screenshot)
  • Use the ssr-sdom-shim module You have to import it only for the tests, before importing the components you test. I am not sure if there is some entry point for the tests, or you will need to add it to all .test.js files, but this is the module that implements shims for missing browser native APIs in jest (jsdom)
import "ui5/webcomponents-base/dist/ssr-dom-shim.js";

ilhan007 avatar Feb 07 '25 11:02 ilhan007

The issue has been resolved with the suggested changes in the application.

ilhan007 avatar Feb 10 '25 07:02 ilhan007

@ilhan007 , I am getting this error in jest tests on my module"

Cannot find module '@ui5/webcomponents-base/jsx-runtime'  ....

This is mentioned as failure 2 - have you fixed this issue? The hack to the package.json should not be necessary to alias a module like this - but i does unblock me.

codefactor avatar Feb 11 '25 21:02 codefactor

This is not just a jest problem I think... I am developing in MeteorJS and getting the same error message - no jest in use... I cannot use any ui5 webcomponents

Greg-Owens avatar Feb 13 '25 18:02 Greg-Owens

I am running 2.7.2

Greg-Owens avatar Feb 13 '25 18:02 Greg-Owens

Same here, we are suing cypress component tests and got this error message when try to update to 2.8.0

TypeError: The following error originated from your test code, not from Cypress.

  > Failed to resolve module specifier "@ui5/webcomponents-base/jsx-runtime". Relative references must start with either "/", "./", or "../".

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

eskimoblood avatar Mar 24 '25 13:03 eskimoblood

Hi, the import @ui5/webcomponents-base/jsx-runtime is specified in base/package.json and all modern build tools should resolve it to https://github.com/SAP/ui5-webcomponents/blob/d3580adacf83d7fa636927f6e6c3b0d20df50d27/packages/base/package.json#L20

What is your cypress setup? Usually in a new project, cypress is using vite and it has support for resolving such references. Jest (and meteor mentioned above) use some really old build tools that do not support conditional exports that are a pretty standard feature nowadays.

So can you share your cypress version and setup? Perhaps update to the latest cypress?

pskelin avatar Mar 25 '25 07:03 pskelin

We use cypress 14.1.0 so mostly up to date. But we use an older version of rollup

here is our setup:

import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import typescript from 'rollup-plugin-typescript2'
import postcss from 'rollup-plugin-postcss'
import dotenv from 'rollup-plugin-dotenv'
import poFileLoader from './rollup_plugins/poFileLoader'
import path from 'path'
import { globSync } from 'glob'

const { babel } = require('@rollup/plugin-babel')

export default {
    input: [
        './cypress/support/component.ts',
        ...globSync(path.resolve(__dirname, 'src/**/*.cy.*'), {
            ignore: '**/node_modules/**',
        }),
    ],
    output: {
        dir: `./cypress/dist`,
        format: 'esm',
        entryFileNames: '[name].js',
        chunkFileNames: '[name].[hash].js',
        sourcemap: true,
    },
    plugins: [
        nodeResolve({ preferBuiltins: false, browser: true }),
        babel({ babelHelpers: 'bundled', exclude: 'node_modules/**' }),
        commonjs(),
        postcss({
            modules: true,
            inject: true,
        }),
        typescript({
            tsconfigOverride: {
                include: [
                    'src/**/*',
                    'cypress.rollup.config.ts',
                    'cypress/support/*',
                ],
                compilerOptions: {
                    declaration: false,
                    declarationDir: 'dts',
                    types: [
                        'cypress',
                        '@ui5/webcomponents-cypress-commands',
                        '@testing-library/cypress',
                    ],
                },
            },
        }),
        poFileLoader(),
        dynamicImportVars(),
        dotenv(),
    ],
    external: [],
}

eskimoblood avatar Mar 25 '25 07:03 eskimoblood

Hi @ilhan007 I used to try this method to make tests run, however, this error occurs in main project in 2.10.0.

Image

Update 2:

We have released 2.7.1 for all packages on the public npm (including the aforementioned ElementInternals shim for jest/jsdom env), but not available on the internal registry https://int.repositories.cloud.sap/artifactory/api/

Once available:

  • Update your package.json, clean node_modules, and install 2.7.1 for all @ui5/* packages (see the screenshot)
  • Add the moduleNameMapper setting in your package.json under jest (see the screenshot)
  • Use the ssr-sdom-shim module You have to import it only for the tests, before importing the components you test. I am not sure if there is some entry point for the tests, or you will need to add it to all .test.js files, but this is the module that implements shims for missing browser native APIs in jest (jsdom)

import "ui5/webcomponents-base/dist/ssr-dom-shim.js";

wilson-xu-sap avatar Jun 09 '25 06:06 wilson-xu-sap

Hello @Ankitadoshi can you check if the solution below works for you (as far as I got the issues are coming from the same project) https://github.com/SAP/ui5-webcomponents/issues/11745#issuecomment-2991578738

ilhan007 avatar Jun 20 '25 13:06 ilhan007

This issue has been closed. To reopen, just leave a comment!

github-actions[bot] avatar Jun 20 '25 13:06 github-actions[bot]