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

Activating extension failed: Must use import to load ES Module #2435

Closed
laike9m opened this issue Dec 6, 2020 · 13 comments · Fixed by #2508
Closed

Activating extension failed: Must use import to load ES Module #2435

laike9m opened this issue Dec 6, 2020 · 13 comments · Fixed by #2508
Labels
editor: theia type: question reporter has a general question

Comments

@laike9m
Copy link

laike9m commented Dec 6, 2020

Describe the bug

When my extension is being activated, it reports the following error

Activating extension 'Cyberbrain' failed: Must use import to load ES Module:
 /tmp/vscode-extensions/[email protected]/extension/out/extension.js require()
 of ES modules is not supported. require()
 of /tmp/vscode-extensions/[email protected]/extension/out/extension.js from
 /theia/node_modules/@theia/plugin-ext/lib/hosted/node/plugin-host-rpc.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 extension.js to end in .cjs, change the requiring code to use import(),
 or remove "type": "module" from /tmp/vscode-extensions/[email protected]/extension/package.json.

The same extension can work in VS Code without any problem, and it used to (around two weeks ago) work in Gitpod as well.

Steps to reproduce

Visit
https://gitpod.io/#snapshot/91475a9d-4ccf-420a-b0ee-11db084ce689
and you'll see the error popup.

Expected behavior

The extension can be activated successfully with no error.

Additional information

Example repository

Repository of my extension:
https://github.com/laike9m/Cyberbrain/tree/master/cyberbrain-vsc

@akosyakov
Copy link
Member

akosyakov commented Dec 7, 2020

It could be related to Node.js version which we are using to deploy Theia: manuelbieh/geolib#208 We switched to Node.js 12.18.3 in last release. Latest VS Code is 12.14.1.

@laike9m
Copy link
Author

laike9m commented Dec 7, 2020

This looks like my issue, but I do need the "type": "module". Any ideas?

@akosyakov
Copy link
Member

Yes removing it will fix the issue. I think the following is happening:

  • in 12.14.1 ES modules are experimental and not enabled by deafult, it is why it works in VS Code
  • in 12.18.3 is already LTS and ES modules are not experimental anymore, so Node will try to respect "type": "module". It is why it does not work for you in Gitpod, as soon as VS Code moves to newer Node.js your extension will have such problem there as well.

@akosyakov akosyakov added type: question reporter has a general question and removed type: bug Something isn't working labels Dec 7, 2020
@akosyakov
Copy link
Member

but it could be a good idea for us to downgrade Node.js to avoid such issues for extensions

@laike9m
Copy link
Author

laike9m commented Dec 7, 2020

By downgrade you mean? My understanding is that the Node.js version is controlled by VS Code, so once it decides to upgrade my extension will break. Or is it?

@akosyakov
Copy link
Member

By downgrade you mean? My understanding is that the Node.js version is controlled by VS Code, so once it decide to upgrade my extension will break. Or is it?

Sorry for the confusion. I meant downgrading Node.js version in Gitpod that all VS Code extensions which working in VS Code now also work in Gitpod.

I think you just should remove "type": "module" now from package.json and deploy a new version.

@laike9m
Copy link
Author

laike9m commented Dec 8, 2020

Got it. To me it seems to makes more sense if Gitpod can keep the Node version the same with VS Code to avoid such issue from happening. And when VS Code upgrades the Node version (and break my extension potentially), I shall fix it, otherwise it's hard to fix it locally.

@laike9m
Copy link
Author

laike9m commented Dec 10, 2020

Any thoughts?

akosyakov added a commit that referenced this issue Dec 11, 2020
for better compatibility of VS Code extensions
@akosyakov
Copy link
Member

PR is there: #2508 but I doubt we will deploy it this year, likely beginning next year.

@laike9m
Copy link
Author

laike9m commented Dec 11, 2020

thanks

akosyakov added a commit that referenced this issue Dec 14, 2020
for better compatibility of VS Code extensions
@akosyakov akosyakov reopened this Dec 14, 2020
@akosyakov
Copy link
Member

The fix was deployed.

@laike9m
Copy link
Author

laike9m commented Feb 9, 2021

VS Code has upgraded the node version to 12.18.3

@akosyakov
Copy link
Member

akosyakov commented Feb 10, 2021

@laike9m thank you for a ping, I will bump it up this month: #3069 (comment)

pavan-tri pushed a commit to trilogy-group/gitpod that referenced this issue Apr 28, 2021
for better compatibility of VS Code extensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor: theia type: question reporter has a general question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants