Description
Currently, a node.js project that declares "type": "module" in the package.json can't use penpot-export with a configuration file.
$ penpot-export
/Users/redradix/Taller/kaleidos-easyfest/penpot-export/packages/cli/dist/bin/index.js:16
var config = require(configFilePath);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/redradix/Taller/kaleidos-easyfest/easyfest/frontend/penpot-export.config.js from /Users/redradix/Taller/kaleidos-easyfest/penpot-export/packages/cli/dist/bin/index.js not supported.
penpot-export.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename penpot-export.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/redradix/Taller/kaleidos-easyfest/easyfest/frontend/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.<anonymous> (/Users/redradix/Taller/kaleidos-easyfest/penpot-export/packages/cli/dist/bin/index.js:16:14) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v18.16.1
This is due to node.js require() interpreting that the .js file is an ES module, even though it's not.
Renaming the configuration file with the .cjs extension won't work, because penpot-export is limited to the exact name of that config. Also, actually writing an ES module in penpot-export.config.js won't work either; it's an issue with the loader.
Workaround
There's a workaround for UNIX systems:
$ mv penpot-export.config.js penpot-export.config.cjs
$ ln -s penpot-export.config.cjs penpot-export.config.js
Expected outcome
penpot-export is able to read configuration files written as CommonJS in a ES modules project, or written as ES module in a CommonJS project.
Opportunity
Consider implementing a more flexible configuration system with cosmicconfig (used by Prettier): https://github.com/cosmiconfig/cosmiconfig
This could be an opportunity to implement a CLI option to load configuration files other that penpot-export.config.js.
Description
Currently, a node.js project that declares
"type": "module"in thepackage.jsoncan't use penpot-export with a configuration file.This is due to node.js
require()interpreting that the.jsfile is an ES module, even though it's not.Renaming the configuration file with the
.cjsextension won't work, because penpot-export is limited to the exact name of that config. Also, actually writing an ES module inpenpot-export.config.jswon't work either; it's an issue with the loader.Workaround
There's a workaround for UNIX systems:
Expected outcome
penpot-export is able to read configuration files written as CommonJS in a ES modules project, or written as ES module in a CommonJS project.
Opportunity
Consider implementing a more flexible configuration system with
cosmicconfig(used by Prettier): https://github.com/cosmiconfig/cosmiconfigThis could be an opportunity to implement a CLI option to load configuration files other that
penpot-export.config.js.