I created a new Vue app using Vite via npm init vue@latest. I added TailwindCSS to the project based on the official guide.
Running npm run lint throws errors
error 'module' is not defined no-undef
because it wants postcss.config.js and tailwind.config.js to be ES modules (I think).
When converting postcss.config.js from
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
to
export const plugins = {
tailwindcss: {},
autoprefixer: {},
};
and tailwind.config.js from
module.exports = {
content: ["./index.html", "./src/**/*.{vue,js,ts,jsx,tsx}"],
theme: {
extend: {},
},
plugins: [],
};
to
export const content = ["./index.html", "./src/**/*.{vue,js,ts,jsx,tsx}"];
export const theme = {
extend: {},
};
export const plugins = [];
and running npm run dev the app crashes with the error
[vite] Internal server error: Unexpected token 'export' Plugin: vite:css
How do I solve this linting error?
You can actually keep those config files as CommonJS. ESLint's env needs to be set to node in those config files because Node is the actual environment during the build.
Insert this comment at the top of postcss.config.js and tailwind.config.js:
/* eslint-env node */
env for *.config.jsConfigure overrides to set env for *.config.js files:
// .eslintrc.cjs
module.exports = {
⋮
overrides: [
{
files: ['*.config.js'],
env: {
node: true,
},
},
],
}
If using VS Code, you'll likely need to restart the ESLint server (or the IDE) to reload the configuration.
*.config.jsConfigure ignorePatterns to not lint these config files:
// .eslintrc.cjs
module.exports = {
⋮
ignorePatterns: ['*.config.js'],
}
If using VS Code, you'll likely need to restart the ESLint server (or the IDE) to reload the configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With