admin管理员组文章数量:1312773
I am configuring my own plugins in Tailwind config file by import ES module with CommonJS syntax require('/my-plugin');
but I get an error when trying to build:
SyntaxError: Cannot use import statement outside a module
at pileFunction (<anonymous>)
Since I am using ES6 statements in the my-plugin
file (e.g import
, export default
) so these causing to throw errors even though I use regular require
statements to import it in my Tailwind config file.
How do I resolve this problem?
My code:
tailwind.config.js
const myPlugin = require('./my-plugin');
module.exports = {
mode: 'jit',
darkMode: 'class',
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./ponents/**/*.{js,ts,jsx,tsx}',
],
theme: {
}
plugins: [
myPlugin(),
],
};
./my-plugin
import ... from ...
const MyPlugin = () => {}
export default MyPlugin
I am configuring my own plugins in Tailwind config file by import ES module with CommonJS syntax require('/my-plugin');
but I get an error when trying to build:
SyntaxError: Cannot use import statement outside a module
at pileFunction (<anonymous>)
Since I am using ES6 statements in the my-plugin
file (e.g import
, export default
) so these causing to throw errors even though I use regular require
statements to import it in my Tailwind config file.
How do I resolve this problem?
My code:
tailwind.config.js
const myPlugin = require('./my-plugin');
module.exports = {
mode: 'jit',
darkMode: 'class',
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./ponents/**/*.{js,ts,jsx,tsx}',
],
theme: {
}
plugins: [
myPlugin(),
],
};
./my-plugin
import ... from ...
const MyPlugin = () => {}
export default MyPlugin
Share
Improve this question
asked Apr 14, 2023 at 19:56
EppleEpple
9821 gold badge12 silver badges33 bronze badges
1 Answer
Reset to default 7Ensure you:
- Are running Tailwind v3.3+ for configuration file ESM format support
- Use the
mjs
extension fortailwind.config.mjs
instead oftailwind.config.js
if you do not have"type": "module"
in the project'spackage.json
- Use ESM syntax in the configuration file
- Add a ma after the
theme
object declaration - Do not execute the
import
ed plugin function
import myPlugin from './my-plugin';
export default {
mode: 'jit',
darkMode: 'class',
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./ponents/**/*.{js,ts,jsx,tsx}',
],
theme: {
},
plugins: [
myPlugin,
],
};
本文标签: javascriptHow to import ES module in Tailwind config fileStack Overflow
版权声明:本文标题:javascript - How to import ES module in Tailwind config file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741898608a2403731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论