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
[esm] avoid depending on require.main #6718
Comments
@b12f Thanks for opening this issue! Actually nuxt was not using babel for ESM support but standard-thing/esm which has almost the same runtime implementation of the node with few enhancements for backward compatibility. ESM support is not still in LTS and not the entire ecosystem is prepared for that. But could be a good idea start experimenting behind a flag :) |
And it wont be for quite of a time, since node 13 not going to be LTS |
We are hoping to backport to 12.x but are not 100% if we'll be able to yet. |
As of Because of this anyone using |
@Jamesernator Both CI and locally using (v12.13.1) I can still use ESM syntax for |
This only affects
I was helping a friend debug their setup, basically the host auto updated to Node Instead of rewriting to CJS, I suggested trying it with This happens because when the entry point is loaded as ESM Now it's not completely dire because I did manage to find a workaround using Given ESM syntax is used in the docs for Nuxt, and |
As @Jamesernator alluded to, after updating to Node v12.16.2 I'm seeing errors in my Configuration:
UPDATE: Actually I'm getting the same issues even with Node 10.x and 12.13.
|
Following up from above: in my case the setup was the issue, not Nuxt core. When using Anyways, re-installing |
So after long time with this issue... |
Hi. Just as an update, we are working on next gen server for nuxt3 (backported to nuxt2) which is using RollupJS to bundle server-middleware and natively supports mjs. In the meantime you can migrate from export default {
createRequire: 'jiti'
} Supporting |
The actual error message was: > ERROR Must use import to load ES Module: /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js > require() of ES modules is not supported. > require() of /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js from /Users/kana/working/hatokurandom/lib/utils.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 lodash.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/kana/working/hatokurandom/node_modules/lodash-es/package.json. According to nuxt/nuxt#6718 (comment) > Hi. Just as an update, we are working on next gen server for nuxt3 > (backported to nuxt2) which is using RollupJS to bundle > server-middleware and natively supports mjs. In the meantime you can > migrate from esm to jiti by setting this in nuxt.config:
I tried the jiti workaround mentioned by @pi0 in OpenLightingProject/open-fixture-library@
It seems that @danielroe @b12f Your reactions suggest that you managed to get ESM working with the workaround. What is the value of the |
@FloEdelmann It works for me with node 14, |
@FloEdelmann You might need to use latest nuxt-edge with jiti 1.x which leverages native resolve for exports field (and createRequire is no longer needed) |
I tried with
Also, I get But apart from that, it seems to work. |
@FloEdelmann Is this still an open issue for you? Do make sure your |
@danielroe The telemetry error still remains though:
|
@FloEdelmann Could you provide a reproduction? I can't reproduce the telemetry error you're talking about. |
@danielroe It happens for me in https://github.com/OpenLightingProject/open-fixture-library/tree/esm, when running |
@FloEdelmann Just checking out https://github.com/OpenLightingProject/open-fixture-library/tree/esm-2 - seems to be working now? |
@danielroe It is working, but it still gives the same warning:
|
@FloEdelmann Ah. Looks like this is purely an issue with |
Issue with telemetry should be fixed in latest release (https://github.com/nuxt/telemetry/releases/tag/v1.3.4) you can update by recreating lockfile or |
The actual error message was: > ERROR Must use import to load ES Module: /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js > require() of ES modules is not supported. > require() of /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js from /Users/kana/working/hatokurandom/lib/utils.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 lodash.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/kana/working/hatokurandom/node_modules/lodash-es/package.json. According to nuxt/nuxt#6718 (comment) > Hi. Just as an update, we are working on next gen server for nuxt3 > (backported to nuxt2) which is using RollupJS to bundle > server-middleware and natively supports mjs. In the meantime you can > migrate from esm to jiti by setting this in nuxt.config:
The actual error message was: > ERROR Must use import to load ES Module: /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js > require() of ES modules is not supported. > require() of /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js from /Users/kana/working/hatokurandom/lib/utils.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 lodash.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/kana/working/hatokurandom/node_modules/lodash-es/package.json. According to nuxt/nuxt#6718 (comment) > Hi. Just as an update, we are working on next gen server for nuxt3 > (backported to nuxt2) which is using RollupJS to bundle > server-middleware and natively supports mjs. In the meantime you can > migrate from esm to jiti by setting this in nuxt.config:
The actual error message was: > ERROR Must use import to load ES Module: /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js > require() of ES modules is not supported. > require() of /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js from /Users/kana/working/hatokurandom/lib/utils.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 lodash.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/kana/working/hatokurandom/node_modules/lodash-es/package.json. According to nuxt/nuxt#6718 (comment) > Hi. Just as an update, we are working on next gen server for nuxt3 > (backported to nuxt2) which is using RollupJS to bundle > server-middleware and natively supports mjs. In the meantime you can > migrate from esm to jiti by setting this in nuxt.config:
The actual error message was: > ERROR Must use import to load ES Module: /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js > require() of ES modules is not supported. > require() of /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js from /Users/kana/working/hatokurandom/lib/utils.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 lodash.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/kana/working/hatokurandom/node_modules/lodash-es/package.json. According to nuxt/nuxt#6718 (comment) > Hi. Just as an update, we are working on next gen server for nuxt3 > (backported to nuxt2) which is using RollupJS to bundle > server-middleware and natively supports mjs. In the meantime you can > migrate from esm to jiti by setting this in nuxt.config:
The actual error message was: > ERROR Must use import to load ES Module: /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js > require() of ES modules is not supported. > require() of /Users/kana/working/hatokurandom/node_modules/lodash-es/lodash.js from /Users/kana/working/hatokurandom/lib/utils.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 lodash.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/kana/working/hatokurandom/node_modules/lodash-es/package.json. According to nuxt/nuxt#6718 (comment) > Hi. Just as an update, we are working on next gen server for nuxt3 > (backported to nuxt2) which is using RollupJS to bundle > server-middleware and natively supports mjs. In the meantime you can > migrate from esm to jiti by setting this in nuxt.config:
What problem does this feature solve?
ESM support just dropped in node 13.2.0, removing the need for a lot of babel transpiling.
What does the proposed changes look like?
There is at least one problem right now that is preventing me from using nuxt with node ESM:
Here,
https://github.com/nuxt/nuxt.js/blob/dev/packages/utils/src/resolve.js#L109
nuxt is trying to access
require.main
, which is not defined when starting a process with esm modules. This throws an error later when trying to accessrequire.main.paths
.Temporary workaround would be to change the line to the following:
And making people explicitly supply the modulesDir option
The text was updated successfully, but these errors were encountered: