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

vscode extension fails to import dynamically due to ESM #736

Closed
shinokada opened this issue May 11, 2023 · 11 comments
Closed

vscode extension fails to import dynamically due to ESM #736

shinokada opened this issue May 11, 2023 · 11 comments
Assignees
Labels
duplicate This issue or pull request already exists scope: inlang/sherlock-vscode Related to source-code/ide-extension. type: bug Something isn't working

Comments

@shinokada
Copy link

Problem

After installing the VSCode extension, I tried for Inline annotations and update translations, but not working.

Expected behavior

Should work as stated in the doc.

Steps to reproduce

/**
 * @type { import("@inlang/core/config").DefineConfig }
 */
export async function defineConfig(env) {
	const { default: jsonPlugin } = await env.$import(
		"https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@latest/dist/index.js"
	)
	const { default: sdkPlugin } = await env.$import(
		"https://cdn.jsdelivr.net/npm/@inlang/sdk-js-plugin@latest/dist/index.js"
	)
	const { default: ideExtensionPlugin } = await env.$import(
		"https://cdn.jsdelivr.net/npm/@inlang/ide-extension-plugin@latest/dist/index.js",
	)
	// const { default: pluginJson } = await env.$import(
	// 	"https://cdn.jsdelivr.net/gh/samuelstroschein/inlang-plugin-json@2/dist/index.js",
	// )

	return {
		referenceLanguage: "en",
		plugins: [
			jsonPlugin({
				pathPattern: "./languages/{language}.json",
			}),
			ideExtensionPlugin(),
			sdkPlugin({
				languageNegotiation: {
					strategies: [{ type: "localStorage" }]
				}
			}),
		],
	}
}
  • highlight a sentence by using CMD ..

Additional information (screenshots?)

image
@shinokada shinokada added the type: bug Something isn't working label May 11, 2023
@samuelstroschein samuelstroschein added the scope: inlang/sherlock-vscode Related to source-code/ide-extension. label May 12, 2023
@felixhaeberle
Copy link
Contributor

@shinokada Thank you for pointing this out! We currently investigating around a build time bug and will fix this soon.

@ivanhofer
Copy link
Contributor

@shinokada if you are using the sdkPlugin then you should get rid of manually specifying ideExtensionPlugin, unless you want to manually configure the behavior.

@felixhaeberle
Copy link
Contributor

felixhaeberle commented May 15, 2023

Debugging status:

Local, everything works fine. In production the following error appear: [inlang.vs-code-extension]Invalid host defined options in the console when you open the Developer Tools within VS Code under Help / Hilfe in the menu bar at the top.

From a Twitter link, I got an interesting info:
https://twitter.com/slicknet/status/1559619176230047744?lang=en

If you’re using Node.js and get a “invalid host defined options” error, it means you’re trying to use v8-compile-cache with ESM modules. That doesn’t work. Sadly the only solution is to remove v8-compile-cache.

@felixhaeberle
Copy link
Contributor

More information on this topic. It seems that there is a module called copy-webpack-plugin in charge of this error. This is the respective StackOverflow question / answer

https://stackoverflow.com/a/70398244/6854385

@felixhaeberle
Copy link
Contributor

@samuelstroschein Created an issue at vscode to investigate further. Frankly, I have no clue what's going on in the VS code internals. 🥲

@felixhaeberle
Copy link
Contributor

This is the error in the vs code console:
Bildschirmfoto 2023-05-15 um 12 36 07

Going to line 76 of the main.cjs is:

`),new Yc(o)}}async function Nw(n){try{Li.capture({distinctId:"unknown",event:"IDE-EXTENSION activated"}),yn("Inlang extension activated.","info"),nh({context:n}),Ee.window.onDidChangeActiveTextEditor(()=>{for(let e of n.subscriptions)e.

Now trying to naively commenting out telemetry and see what happens.

@felixhaeberle
Copy link
Contributor

felixhaeberle commented May 15, 2023

When commenting out the telemetry part, this is what happens:

Bildschirmfoto 2023-05-15 um 13 00 57

The line on main.cjs 8585 is:

    m = await import(a),
    h = await Ns({ module: m, env: d }),

This seems to be the reason: import statement is not natively supported in CommonJS (CJS) modules.
@samuelstroschein How should we proceed here? Introduce a Babel transpilation?

Edit: Fake News: dynamic import is supported in commonjs, I was tricked by an old article. I have no clue why this doesn't work then.

@samuelstroschein
Copy link
Member

samuelstroschein commented May 15, 2023

@felixhaeberle This is bad.

It seems like vscode (in production) is not supporting providing an import callback. Maybe for safety reasons, maybe because it's a bug. Have you skimmed through the VSCode repo if other ppl filed similar issues?

Edit: The bug is on stack overflow with no answers https://stackoverflow.com/questions/75002605/vscode-extension-a-dynamic-import-callback-was-not-specified

Edit 2: Found it microsoft/vscode#130367

@felixhaeberle
Copy link
Contributor

@samuelstroschein This is the issue we are already subscribed to, but I though it would have been resolved through the update of electron in the latest release? They haven't closed it yet so maybe we have to wait more.

@samuelstroschein samuelstroschein changed the title VSCode extension not showing vscode extension fails to import dynamically due to ESM May 15, 2023
@felixhaeberle
Copy link
Contributor

felixhaeberle commented May 15, 2023

just to have a complete history here: also linking our too early closed issue of dynamic imports.
Tested it only locally back then. #452

@samuelstroschein
Copy link
Member

@felixhaeberle The issue we subscribed to was the update of Electron to a node version that supports data: imports.

Indeed, this is the old issue #452. Thus let's close this one here as duplicate.

@samuelstroschein samuelstroschein closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2023
@samuelstroschein samuelstroschein added the duplicate This issue or pull request already exists label May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists scope: inlang/sherlock-vscode Related to source-code/ide-extension. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants