Skip to content

Conversation

modern-dev-dude
Copy link

Issue #, if available:
When compiling consuming packages to ESM using tsc, the following errors appeared at runtime

Error: Dynamic require of "console" is not supported
Error: Dynamic require of "url" is not supported

package.json in consuming

{
  "type": "module"
}

tsconfig in consuming package:

"jsx": "react",
"rootDir": "./src",
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"target": "es2022",
"esModuleInterop": true,
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"module": "NodeNext",
"outDir": "dist",
"sourceMap": true,
"verbatimModuleSyntax": true,
"declaration": true,
"lib": ["es2022"]

Description of changes:

  • removes the import url = require('url') and adds import url from 'url'
  • removes the import of Console and changes the constructor to new console.Console leveraging the global variable at runtime

Thanks for taking time to review! :)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant