iobroker-javascript-vs-code-extension icon indicating copy to clipboard operation
iobroker-javascript-vs-code-extension copied to clipboard

FR: Support for require statement

Open stevenengland opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. In the IDE the require statement is not supported. See here: image

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

stevenengland avatar Oct 03 '23 07:10 stevenengland

Can you please try the following:

  1. Add the new file polyfill.d.ts in .iobroker/types/
  2. Add the following content to the new file
export {};

declare global {
    function require(library: string): any;
}
  1. 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.

nokxs avatar Oct 11 '23 20:10 nokxs

Thanks, @nokxs, that worked for me.

neopholus avatar Mar 29 '24 07:03 neopholus