Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent issue when extract or compile : Error [ERR_REQUIRE_ESM]: require() of ES Module #43

Open
Wewill opened this issue Mar 1, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@Wewill
Copy link

Wewill commented Mar 1, 2023


> vue-gettext-compile

/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/loaders.js:32
    throw error;
                                                          ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/wilhemarnoldy/Developpements/Berlioz/gettext.config.js from /Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/loaders.js not supported.
gettext.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 gettext.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/wilhemarnoldy/Developpements/Berlioz/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at module.exports (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/import-fresh/index.js:32:59)
    at loadJs (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/loaders.js:16:18)
    at ExplorerSync.loadFileContentSync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:84:26)
    at ExplorerSync.createCosmiconfigResultSync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:89:30)
    at ExplorerSync.loadSearchPlaceSync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:70:25)
    at ExplorerSync.searchDirectorySync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:55:32)
    at run (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:35:27)
    at cacheWrapperSync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/cacheWrapper.js:28:18)
    at ExplorerSync.searchFromDirectorySync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:47:49)
    at ExplorerSync.searchSync (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/cosmiconfig/dist/ExplorerSync.js:27:25)
    at loadConfig (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/vue3-gettext/dist/bin/gettext_compile.js:105:30)
    at Object.<anonymous> (/Users/wilhemarnoldy/Developpements/Berlioz/node_modules/vue3-gettext/dist/bin/gettext_compile.js:144:14) {
  code: 'ERR_REQUIRE_ESM'
}


Package version is : 2.4.0

Thanks a lot

@lzurbriggen lzurbriggen added the bug Something isn't working label Mar 1, 2023
@lzurbriggen
Copy link
Collaborator

@Wewill thanks for reporting this. i was no aware that this was an issue, but I'm working on esm-related stuff in #41 that should fix this aswell.

i don't quite remember how I set up cosmiconfig (and i'll replace it soon), but here are 2 ideas you could try in the meantime (I have no idea if any of this will work):

  • rename the file to gettext.config.cjs
  • rename the file to gettext.config.json and write the config as json instead of js

@Wewill
Copy link
Author

Wewill commented Mar 1, 2023

Thanks a lot @lzurbriggen for your quick reply.
Renaming the file to gettext.config.cjs is quickly fixing the issue !
Thanks again !

@youthlin
Copy link
Contributor

youthlin commented Mar 3, 2023

Can we use gettext.config.ts after #41 ~
so that we can use code hint

export default defineGettextConfig({
...
})

@lzurbriggen
Copy link
Collaborator

@youthlin i will try to implement a ts-node based loader to enable this. i don't have a lot of time at the moment, so all of that will probably take a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants