Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

typescript - Vite/Tailwind Import colors.js into tailwind.config.js

Can't use CommonJS require in Vite (which is ES6), but can't seem to use import either as the build process complains that you cannot use import from outside a module (tailwind.config.js)

const colors = require('tailwindcss/colors') // throws error that require is CommonJS
import colors from 'tailwindcss/colors' // throws error: cannot import from outside a module


module.exports = {
    purge: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
    darkMode: false, // or 'media' or 'class'
    theme: {
        colors: {
            gray: colors.coolGray,
            teal: colors.teal,
            green: colors.green,
            cyan: colors.cyan,
            blue: colors.lightBlue,
            indigo: colors.indigo,
            white: colors.white
        },
        extend: {},
    },
    variants: {
        extend: {},
    },
    plugins: [
    ]
}

Help appreciated...

question from:https://stackoverflow.com/questions/65850146/vite-tailwind-import-colors-js-into-tailwind-config-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I've the same setup using require and it's not an error it's just a tip given by the editor, it considers it as source code not a config, you could disable it in settings.json inside the .vscode folder in project root by adding:

{
    "javascript.validate.enable": true,
    "javascript.suggestionActions.enabled": false
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...