preactjs/wmr

Failed to load wmr.config.ts

Aloento opened this issue ยท 4 comments

Describe the bug
yarn create wmr
rename wmr.config.mjs to wmr.config.ts
then:

Error: Failed to load wmr.config.ts
Error [ERR_REQUIRE_ESM]: require() of ES Module .\node_modules\wmr\index.js from .\wmr.config.js not supported.
Instead change the require of index.js in .\wmr.config.js to a dynamic import() which is available in all CommonJS modules.
TypeError [ERR_INVALID_ARG_TYPE]: The "id" argument must be of type string. Received an instance of URL

Bug occurs with:

  • wmr or wmr start (development)
  • wmr build (production)
  • wmr serve

Desktop (please complete the following information):

  • OS: Win 11
  • Node Version: 17
  • WMR Version: newest

You could add "type": "module" to your package.json if you want to use a TS config at the moment.

We could ship a CJS version of the DefineConfig to fix this. Should be fine to do I imagine.

Do we support .ts for configs?

Yes, we do. It can end up transpiled to CJS though, which results in that require():

if (ext === '.ts') {
// Create a temporary file to write compiled output into
// TODO: Do this in memory
configFile = resolve(options.cwd, 'wmr.config.js');
await compileSingleModule(file, {
out: resolve('.'),
hmr: false,
rewriteNodeImports: false,
format: pkg && pkg.type === 'module' ? 'es' : 'commonjs'
});
}

Going to reopen this as it's a legitimate issue that hasn't yet been fixed.