Skip to content

require.context crashes in main.ts #2531

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

Closed
sandiprb opened this issue Sep 16, 2018 · 3 comments
Closed

require.context crashes in main.ts #2531

sandiprb opened this issue Sep 16, 2018 · 3 comments

Comments

@sandiprb
Copy link

sandiprb commented Sep 16, 2018

Version

3.0.1

Node and OS info

Node v8.11.3 / Yarn 1.3.2 / Mac OSX

Steps to reproduce

code snippet:

const requireComponents = require.context('./components/common/', false, '/\.vue$/') 

now while doing yarn serve it breaks the build with error

ERROR in src/main.ts
9:34 Property 'context' does not exist on type 'NodeRequire'.

What is expected?

require.context should be allowed in ts definitions for import.

What is actually happening?

context method no available on NodeRequire

@LinusBorg
Copy link
Member

Please provide a repository with project using the exact code that causes this error.

@LinusBorg LinusBorg added the needs reproduction This issue is missing a minimal runnable reproduction, provided by the author label Sep 16, 2018
@haoqunjiang
Copy link
Member

  1. The last parameter of require.context should be RegExp rather than string
  2. Could be fixed by running yarn add @types/webpack-env and add "@types/webpack-env" to the types field in tsconfig.json

@haoqunjiang haoqunjiang added scope: typescript and removed needs reproduction This issue is missing a minimal runnable reproduction, provided by the author labels Sep 16, 2018
@sandiprb
Copy link
Author

@sodatea that worked perfectly fine. Thank you!

kazupon added a commit to intlify/vue-cli-plugin-i18n that referenced this issue Feb 22, 2019
kazupon added a commit to intlify/vue-cli-plugin-i18n that referenced this issue Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants