Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require() of ES modules is not supported #1452

Closed
its-dibo opened this issue Sep 11, 2021 · 4 comments
Closed

require() of ES modules is not supported #1452

its-dibo opened this issue Sep 11, 2021 · 4 comments

Comments

@its-dibo
Copy link

I have an issue when I try to run webpack with webpack.config.ts written in typescript and ts-node has "require": ["tsconfig-paths/register"]

// tsconfig.json

{
  compilerOptions:{
    paths: { /* ----------------- */ }
  },
 'ts-node':{
   "require": ["tsconfig-paths/register"],
   "compilerOptions": {
      "sourceMap": false,
      "module": "commonjs"
    }
}
}

when I remove "require": ["tsconfig-paths/register"] from ts-node it runs, but webpack cannot detect aliases.

I already set module: commonjs in my tsconfig.json and removed type: module from my package.json

trace

> webpack

(node:5932) Warning: require() of ES modules is not supported.
require() of /home/node_modules/colorette/index.js from /home/node_modules/webpack-cli/lib/utils/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /home/node_modules/colorette/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/node_modules/colorette/package.json.
(node:5932) UnhandledPromiseRejectionWarning: /home/node_modules/colorette/index.js:28
export const options = Object.defineProperty({}, "enabled", {
^^^^^^

SyntaxError: Unexpected token 'export'
    at new Script (vm.js:84:7)
    at NativeCompileCache._moduleCompile (/home/node_modules/v8-compile-cache/v8-compile-cache.js:240:18)
    at Module._compile (/home/node_modules/v8-compile-cache/v8-compile-cache.js:184:36)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
    at Module.load (internal/modules/cjs/loader.js:811:32)
    at Function.Module._load (internal/modules/cjs/loader.js:723:14)
    at Module.require (internal/modules/cjs/loader.js:848:19)
    at require (/home/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at Object.get colors [as colors] (/home/node_modules/webpack-cli/lib/utils/index.js:3:16)
    at Object.error (/home/node_modules/webpack-cli/lib/utils/logger.js:5:58)
(node:5932) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:5932) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
`
@cspotcode
Copy link
Collaborator

If this is a tsconfig-paths bug, then it should be reported on their issue tracker. Is that the case?

@its-dibo
Copy link
Author

I'm not sure, however tsconfig-path complains about using ES modules which be handled by ts-node not by them.

@cspotcode
Copy link
Collaborator

cspotcode commented Sep 12, 2021 via email

@its-dibo
Copy link
Author

its-dibo commented Sep 12, 2021

big thanks for your quick response,
as mentioned in the error trace, you (or maybe tsconfig-paths) try to require colorette/index.js not index.cjs and it is an ES module due to type: module in their package.json

I already opened an issue there
I don't want to use ES module at all, so I defined module: commonjs in my tsconfig.json file
so, all trace should use commonjs only

however, how to solve this issue from my side?

@TypeStrong TypeStrong locked and limited conversation to collaborators Sep 19, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants