Hi all!
This appears to be like I’m missing something really simple, but I can’t figure out what.
In my ./layouts/_default/baseof.html
, I have:
<!doctype html>
<!--suppress CssUnknownTarget, HtmlUnknownAttribute, HtmlUnknownTarget -->
<html
class = "h-full overflow-hidden w-full"
lang = "en">
<head>
<!-- other stuff -->
<script
src = "{{- (resources.Get "js/bundle.js" | babel | js.Build | minify).RelPermalink -}}"
defer>
</script>
</head>
<body>
<!-- contents -->
</body>
</html>
I have my tailwind.config.js
file in the root of the project along with config.toml
.
I have my JavaScript file in ./assets/js/bundle.js
:
/* rest of the code */
const tailwindConfig = preval`
const config = require('tailwindcss/resolveConfig')(require('../tailwind.config.js')).theme
module.exports = {
'height-14': parseFloat(config.height['14']),
'screen-sm': parseInt(config.screens.sm)
}
I have that setup as per Tailwind’s documentation here: Configuration - Tailwind CSS
Now when I try to run hugo
(or hugo server
), I get the following errors:
hugo
Start building sites …
hugo v0.92.0+extended darwin/amd64 BuildDate=unknown
Error: Error building site: BABEL: failed to transform "js/bundle.js" (application/javascript): Error: /Users/hrishikesh/Desktop/ts-v3/js/bundle.js: Cannot find module '../tailwind.config.js'
Require stack:
- /Users/hrishikesh/Desktop/ts-v3/js/bundle.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/module-types.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/configuration.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/options.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/bin/babel.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/hrishikesh/Desktop/ts-v3/js/bundle.js:2:57)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at requireFromString (/Users/hrishikesh/Desktop/ts-v3/node_modules/require-from-string/index.js:28:4)
at requireFromString (/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js:21:13)
at getReplacement (/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js:39:15)
at PluginPass.TaggedTemplateExpression (/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/index.js:75:29) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/hrishikesh/Desktop/ts-v3/js/bundle.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/module-types.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/configuration.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/options.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/bin/babel.js'
]
}
: failed to execute binary "npx" with args [--no-install babel --filename=js/bundle.js --out-file=/var/folders/q_/6x14rln918d83wdhb2hz0nfr0000gn/T/compileOut-1481260051.js]: Error: /Users/hrishikesh/Desktop/ts-v3/js/bundle.js: Cannot find module '../tailwind.config.js'
Require stack:
- /Users/hrishikesh/Desktop/ts-v3/js/bundle.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/module-types.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/configuration.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/options.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/index.js
- /Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/bin/babel.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/hrishikesh/Desktop/ts-v3/js/bundle.js:2:57)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at requireFromString (/Users/hrishikesh/Desktop/ts-v3/node_modules/require-from-string/index.js:28:4)
at requireFromString (/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js:21:13)
at getReplacement (/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js:39:15)
at PluginPass.TaggedTemplateExpression (/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/index.js:75:29) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/hrishikesh/Desktop/ts-v3/js/bundle.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/helpers.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/babel-plugin-preval/dist/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/module-types.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/configuration.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/config/files/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/core/lib/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/options.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/lib/babel/index.js',
'/Users/hrishikesh/Desktop/ts-v3/node_modules/@babel/cli/bin/babel.js'
]
}
Total in 2364 ms
However, this works if I change:
require('../tailwind.config.js')
to
require('./tailwind.config.js')
and move the bundle.js
file from ./assets/js/bundle.js
to ./assets/bundle.js
(and update the reference in ./layouts/_default/baseof.html
).
According to Hugo docs:
Any imports in a file outside
/assets
or that does not resolve to a component inside/assets
will be resolved by ESBuild with the project directory as the resolve directory (used as the starting point when looking fornode_modules
etc.)
when I move my file into ./assets/js/
, I should be getting the root of the project as the parent folder. But that doesn’t seem to work. What could I be doing wrong?