Skip to content

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

@Lehoczky

Description

@Lehoczky
Contributor

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

Activity

ota-meshi

ota-meshi commented on Jun 30, 2024

@ota-meshi
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

ota-meshi commented on Jun 30, 2024

@ota-meshi
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

Lehoczky commented on Jun 30, 2024

@Lehoczky
ContributorAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ota-meshi@Lehoczky

      Issue actions

        `TypeError: require is not a function` when running `npm run docs:watch` locally · Issue #2492 · vuejs/eslint-plugin-vue