vite-plugins icon indicating copy to clipboard operation
vite-plugins copied to clipboard

vite-plugin-require-context - TypeScript

Open Liwoj opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

When I use vite-plugin-require-context plugin in my app, TypeScript throws an error "Property 'context' does not exist on type 'NodeRequire'."

Describe the solution you'd like

Some d.ts to use and augment the type system so require.context is not unknown to TS

Describe alternatives you've considered

I'v of course tried to augment NodeRequire interface but without success

Additional context

Pls provide some clear way how to use this plugin in a TypeScript project

Liwoj avatar Sep 12 '22 15:09 Liwoj

Hi @Liwoj It will be appreciated if you can provide some detailed code to reproduce this. :)

IMO this is just a plugin used in vite, and it does not have any compatibility issues of TypeScript/JavaScript.

PeterAlfredLee avatar Sep 20 '22 07:09 PeterAlfredLee

Reproduction

  1. Open
  2. Open new terminal
  3. run npm run check
src/App.vue:2:25 - error TS2339: Property 'context' does not exist on type 'NodeRequire'.

2 const imports = require.context('./components');

Liwoj avatar Sep 20 '22 09:09 Liwoj

Reproduction

  1. Open
  2. Open new terminal
  3. run npm run check
src/App.vue:2:25 - error TS2339: Property 'context' does not exist on type 'NodeRequire'.

2 const imports = require.context('./components');

Any update on that?

iskendev avatar Oct 27 '22 09:10 iskendev