static import of admin modules gives an error
See original GitHub issueDescription
Dynamic import of admin modules works fine, used like here: https://github.com/api-platform/api-platform/blob/62ae3e62685d3b7500049606f7acb9e25dd7fe49/pwa/pages/admin/index.tsx#L9
But static import gives error:
// pages/admin/index.tsx
import Head from "next/head";
import { useEffect, useState } from "react";
import { ListGuesser } from "@api-platform/admin";
const MyList = props =>
<ListGuesser {...props} hasShow={false} />;
const Admin = () => {
(...)
Uncaught Error: require() of ES Module /srv/app/node_modules/.pnpm/@api-platform+api-doc-parser@0.15.7/node_modules/@api-platform/api-doc-parser/lib/cjs/index.js from /srv/app/node_modules/.pnpm/@api-platform+admin@3.3.5_q3lhx7j73grdkfcigv3e6242um/node_modules/@api-platform/admin/lib/cjs/hydra/dataProvider.js not supported.
index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /srv/app/node_modules/.pnpm/@api-platform+api-doc-parser@0.15.7/node_modules/@api-platform/api-doc-parser/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
As a workaround I can create MyList component inside Admin component using dynamically imported modules, but without additional trics like useRef
passing it as a prop to ResourceGuesser force it to render every time.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Error [ERR_MODULE_NOT_FOUND]: Cannot find module
This answer was the one that helped me! I was using import and the file was .js - Adding --es-module-specifier-resolution=node saved the day...
Read more >The specified module 'Module Name' was not loaded because ...
Problem: When trying to import the PnP PowerShell module, I got an error message “Import-Module: The specified module 'SharePointPnPPowerShellOnline' was ...
Read more >Dynamic Import, Code Splitting, Lazy Loading, and Error ...
This article is a detailed guide on how to use dynamic import, which enables code splitting and lazy loading. It also describes how...
Read more >types/express-serve-static-core 4.17.20 causing build ... - GitHub
I tried using the @types/express-serve-static-core package and had problems. I tried using the latest stable version of tsc.
Read more >Application Error Loading 'Successfully Deployed' Web App ...
I recently added my first static files for my sjango App. Everything works when I perform py manage.py runserver to test the app...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe it was not a good idea to add
type: module
in theapi-doc-parser
😅It was not updated yet 😉 Great to know that it works! All the module changes are hard to follow and it’s very difficult to make a compatible library.