Open yovanoc opened 2 years ago
I have a similar scenario where I'm including a dependency i18next which depends on @babel/runtime
.
In the produced index.cjs
file, we see an attempt to require the ESM for these files:
// node_modules/i18next/dist/esm/i18next.js
var import_typeof = __toESM(require("@babel/runtime/helpers/esm/typeof"), 1);
var import_classCallCheck = __toESM(require("@babel/runtime/helpers/esm/classCallCheck"), 1);
var import_createClass = __toESM(require("@babel/runtime/helpers/esm/createClass"), 1);
var import_assertThisInitialized = __toESM(require("@babel/runtime/helpers/esm/assertThisInitialized"), 1);
var import_inherits = __toESM(require("@babel/runtime/helpers/esm/inherits"), 1);
var import_possibleConstructorReturn = __toESM(require("@babel/runtime/helpers/esm/possibleConstructorReturn"), 1);
var import_getPrototypeOf = __toESM(require("@babel/runtime/helpers/esm/getPrototypeOf"), 1);
var import_defineProperty = __toESM(require("@babel/runtime/helpers/esm/defineProperty"), 1);
var import_toArray = __toESM(require("@babel/runtime/helpers/esm/toArray"), 1);
This results in an error:
var import_typeof = __toESM(require("@babel/runtime/helpers/esm/typeof"), 1);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@babel/runtime/helpers/esm/typeof.js from node_modules/utils-lib/dist/index.cjs not supported.
Instead change the require of typeof.js in node_modules/utils-lib/dist/index.cjs to a dynamic import() which is available in all CommonJS modules.
Appears related to https://github.com/egoist/tsup/issues/628
Essentially, this is a problem caused by transitive dependencies that may not be in the same format as the bundle. I suppose this is the fault of the initial dependency in some sense. To solve my problem, I ended up adding @babel/runtime
to my list of noExternals
manually so it would be properly inlined.
First of all my entire codebase is in TS. I have an api which is in CJS. It imports a
common
library in my Monorepo that is in originally in ESM. (type: module in package.json) but this is build with tsup in js files in esm and cjs. BUT the problem is that my Time.cjs file import another file (Random.js) in mycommon
lib and I think tsup don't correctly link this. It keeps the Random.js instead of Random.cjs. Or maybe am I missing something? Thanks in advance for the help.Upvote & Fund