gxmari007 / vite-plugin-eslint

🚨 ESLint plugin for vite
MIT License
266 stars 44 forks source link

error: eslintPlugin is not a function #18

Closed ghost closed 1 year ago

ghost commented 2 years ago

Describe the bug 🐛

I'm currently refactoring a legacy project 👎 Everything is fine until I decide to add code linting. Because this application is powered by Vite, obviously I must add vite-plugin-eslint as a devDependency.

After running build command, I got error TypeError: eslintPlugin is not a function.

 

Reproduce

yarn add --dev vite-plugin-eslint

Changing vite.config.js to:

...
import eslintPlugin from 'vite-plugin-eslint'
...
export default defineConfig({
    plugins: [
        ...,
        eslintPlugin(),
    ],
})

Then running build command.

 

Logs

failed to load config from C:\Users\ASUSVIVOBOOK\OneDrive\Documents\GitHub\mac-os-monterey\vite.config.ts
error during build:
TypeError: eslintPlugin is not a function
    at file:///C:/Users/ASUSVIVOBOOK/OneDrive/Documents/GitHub/mac-os-monterey/vite.config.ts.js?t=1637721861012:47:5
    at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
    at async Loader.import (node:internal/modules/esm/loader:178:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:437:15)
    at async loadConfigFromFile (C:\Users\ASUSVIVOBOOK\OneDrive\Documents\GitHub\mac-os-monterey\node_modules\vite\dist\node\chunks\dep-e0fe87f8.js:68598:31)
    at async resolveConfig (C:\Users\ASUSVIVOBOOK\OneDrive\Documents\GitHub\mac-os-monterey\node_modules\vite\dist\node\chunks\dep-e0fe87f8.js:68188:28)
    at async doBuild (C:\Users\ASUSVIVOBOOK\OneDrive\Documents\GitHub\mac-os-monterey\node_modules\vite\dist\node\chunks\dep-e0fe87f8.js:42986:20)
    at async build (C:\Users\ASUSVIVOBOOK\OneDrive\Documents\GitHub\mac-os-monterey\node_modules\vite\dist\node\chunks\dep-e0fe87f8.js:42974:16)
    at async CAC.<anonymous> (C:\Users\ASUSVIVOBOOK\OneDrive\Documents\GitHub\mac-os-monterey\node_modules\vite\dist\node\cli.js:737:9)

 

System information

System:
    OS: Windows 11 Version Dev
Binaries:
    Node: 16.11.1
    yarn: 3.1.0
Packages:
    "svelte": "^3.44.2",
    "typescript": "^4.5.2",
    "vite": "2.6.14",
    "rollup": "^2.60.1",
    "vite-plugin-eslint": "^1.3.0"
YankeeTube commented 2 years ago

same issue

AliakseiPuchyk commented 2 years ago

I faced the same issue when I tried to use ES modules without babel.

Jakobud commented 2 years ago

I got this to work with using eslintPlugin.default() instead. However I'm trying to use this with Svelte and don't get any linting errors showing up.

awacode21 commented 2 years ago

I am dealing with the same problem when using "type": "module" in package.json for using esm modules. With that change this error occurs. but i need to change to ESM because quite some packages i use are ESM only in their newest versions. So.. seems like i cannot use linting?

@Jakobud sadly using eslintPlugin.default() does not fix it for me.

gxmari007 commented 1 year ago

Now exports correctly according to different environments.