Removed the type="module" key from the package's package.json files
👆 This is the primary change that resolved the issue. The following changes were downstream of this change. Once this change was made the import worked again as expected:
Renamed the package's lib/*.cjs file to lib/*.js.
👆 The use of the .cjs extension is no longer required because the module type is no longer explicitly defined. Consumer's bundlers will be able to resolve both the es and cjs modules appropriately with standard .js extensions now.
Renamed the package's rollup.config.js files to rollup.config.mjs
👆 Because the module type is longer explicitly defined, CommonJS is the default node environment for each package. This means that we need a .mjs to use es modules in all of the local node scripts.
Removed the c8 node --test-reporter=spec --loader part of the core test script
🚨 I was unable to get the existing tests to work with the current configuration/setup and the aforementioned changes. I found the the tsx command worked fine on its own. However, there was some issue loading tsx through node that was preventing it from resolving the modules properly. I looked into it and it turns out that --loader option is actually experimental and may be removed. In fact, there is an existing warning about it in the console when the tests are run:
Obviously, I do not expect you to accept these updates without code coverage of your tests. However, I think this might be a good opportunity to resolve both issues (removal of --loader and type="module"). I am confident that an alternative methods or tool would work. FWIW, I have had great success with Jest and Vitest. If it would be helpful, I'd even be willing to do some of the footwork.
Related issue: #1050
Summary of the changes
type="module"
key from the package'spackage.json
files 👆 This is the primary change that resolved the issue. The following changes were downstream of this change. Once this change was made the import worked again as expected:lib/*.cjs
file tolib/*.js
. 👆 The use of the.cjs
extension is no longer required because the module type is no longer explicitly defined. Consumer's bundlers will be able to resolve both the es and cjs modules appropriately with standard.js
extensions now.rollup.config.js
files torollup.config.mjs
👆 Because the module type is longer explicitly defined, CommonJS is the default node environment for each package. This means that we need a.mjs
to use es modules in all of the local node scripts.c8 node --test-reporter=spec --loader
part of the core test script 🚨 I was unable to get the existing tests to work with the current configuration/setup and the aforementioned changes. I found the thetsx
command worked fine on its own. However, there was some issue loadingtsx
through node that was preventing it from resolving the modules properly. I looked into it and it turns out that--loader
option is actually experimental and may be removed. In fact, there is an existing warning about it in the console when the tests are run:Obviously, I do not expect you to accept these updates without code coverage of your tests. However, I think this might be a good opportunity to resolve both issues (removal of
--loader
andtype="module"
). I am confident that an alternative methods or tool would work. FWIW, I have had great success with Jest and Vitest. If it would be helpful, I'd even be willing to do some of the footwork.