is it possible to execute truffle commands inside a folder in "ESM mode", i.e. package.json contains "type": "module", uses import instead of require etc.?
Here is what I get when I run a truffle command inside such a project:
$ truffle migrate --network mainnet --reset
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /var/MyESMFolder/truffle/truffle-config.js
require() of ES modules is not supported.
require() of /var/MyESMFolder/truffle/truffle-config.js from /usr/local/lib/node_modules/truffle/node_modules/original-require/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 truffle-config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /var/MyESMFolder/package.json.
at new NodeError (node:internal/errors:363:5)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1126:13)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at Object.require (node:internal/modules/cjs/helpers:93:18)
I followed the advice stated in the error message Instead rename truffle-config.js to end in .cjs,
but it only makes the truffle-config file invisible:
$ truffle migrate --network mainnet --reset
Could not find suitable configuration file.
Truffle v5.4.1 (core: 5.4.1)
Node v16.3.0
So truffle-config.cjs
is not "seen" by Truffle at all due to the "wrong" extension; apparently it must be called exactly truffle-config.js
and nothing --absolutely nothing!-- else?!
Is there a hidden/undocumented option to specify a different config filename in truffle? Or any other known way to run truffle from inside an ESM folder?
Note: Truffle is installed globally (npm i -g truffle
)
I can't possibly be the first one to run into this... Any help appreciated!