iobroker-javascript-vs-code-extension
iobroker-javascript-vs-code-extension copied to clipboard
FR: Support for require statement
Is your feature request related to a problem? Please describe.
In the IDE the require statement is not supported. See here:
Describe the solution you'd like
- Maybe this is only a matter of configuration in VSCode then please provide a how to ;)
- If a new feature is needed, please have a look if that can be supported
Can you please try the following:
- Add the new file
polyfill.d.ts
in.iobroker/types/
- Add the following content to the new file
export {};
declare global {
function require(library: string): any;
}
- Modify ./tsconfig.json and add
".iobroker/types/polyfill.d.ts"
to the includes. If the file wasn't changed by yourself it should look like this:
{
"compileOnSave": true,
"compilerOptions": {
"noEmit": true,
"allowJs": true,
"checkJs": true,
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true,
"strict": true,
"noImplicitAny": false,
"target": "es2018",
"typeRoots": [
".iobroker/types",
"node_modules/@types"
]
},
"include": [
"scripts/**/*.js",
"scripts/**/*.ts",
"scripts/global/devices/environment-sensor.ts",
".iobroker/types/javascript.d.ts",
".iobroker/types/polyfill.d.ts"
],
"exclude": [
"node_modules/**"
]
}
Now the require statement should be recognized. If it is working for you I will add the new polyfill in the next version of the extension.
Thanks, @nokxs, that worked for me.