Skip to content

TypeError: require is not a function when running npm run docs:watch locally #2492

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
Lehoczky opened this issue Jun 29, 2024 · 3 comments · Fixed by #2493
Closed

TypeError: require is not a function when running npm run docs:watch locally #2492

Lehoczky opened this issue Jun 29, 2024 · 3 comments · Fixed by #2493

Comments

@Lehoczky
Copy link
Contributor

Lehoczky commented Jun 29, 2024

I've tried to contribute to the documentation, but when I run npm run docs:watch, I only get a blank page with the following error:

Uncaught TypeError: require is not a function
    at index.js:9:9

image

What I did:

  • installed dependencies with npm install
  • ran npm run docs:watch

I've also tried to build the library with npm run tsc, but got the following error:

lib/rules/order-in-components.js:265:25 - error TS7006: Parameter 'fixer' implicitly has an 'any' type.

265     function* handleFix(fixer, propertyNode, unorderedPropertyNode) {
                            ~~~~~


Found 1 error in lib/rules/order-in-components.js:265

I'm on:

  • Windows 10
  • Node v20.15.0
@ota-meshi
Copy link
Member

I don't use Windows so I don't know what the problem is 🤔
The require function should be resolved in the vite plugin we make, so the problem may be here.

export function viteCommonjs(): Plugin {

@ota-meshi
Copy link
Member

I've also tried to build the library with npm run tsc, but got the following error:

We don't constantly monitor tsc errors, we just look at them occasionally and fix them.

https://eslint.vuejs.org/developer-guide/#jsdoc-type-checking-with-typescript

@Lehoczky
Copy link
Contributor Author

It looks like Vite is not processing the library files because the libRoot variable has Windows file separators in them, but Vite passes file paths to plugins with linux file separators.

This will always be true:

async transform(code, id) {
   if (!id.startsWith(libRoot)) {
        return undefined
    }
}

Because:
libRoot is "C:/Users/.../Projects/eslint-plugin-vue/lib"
but Vite passes this path as the id parameter: "C:\Users\...\Projects\eslint-plugin-vue\lib"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants