PostCSS - "Error: cannot find module 'tailwindcss'"

Hi,

I started from a new site:

$ hugo new site foo
$ cd foo
$ hugo mod init foo

added this to config.toml:

[[module.imports]]
path="github.com/bep/hugo-starter-tailwind-basic/v2"

ran npm commands:

$ hugo mod get
$ hugo mod npm pack
$ npm install
$ npm install -g postcss postcss-cli autoprefixer

Running hugo server gives an error:

Error: Error building site: POSTCSS: failed to transform "css/styles.css" (text/css): Error: Cannot find module 'tailwindcss'

Am I using the theme correctly? I’m using hugo-extended v0.88.1.

I think you missed a step (npm install). Start over.

hugo new site bar
cd bar
hugo mod init bar

Add this to config.toml

[build]
writeStats = true

[[module.imports]]
path="github.com/bep/hugo-starter-tailwind-basic/v2"

Then

hugo mod npm pack
npm install
hugo server

Thanks for the suggestion, but I definitely ran npm install right after hugo mod npm pack and I have a populated foo/node_modules directory that includes tailwindcss.

Here’s my hugo env

hugo v0.88.1-5BC54738+extended windows/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.16.7"

I am unable to reproduce the problem under Linux or Windows. Here’s my Windows environment.

hugo v0.88.1-5BC54738 windows/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio
GOOS="windows"      
GOARCH="amd64"      
GOVERSION="go1.16.7"

You might try deleting the node_modules directory, then run npm install again.

And you do not need to run npm install -g postcss postcss-cli autoprefixer. These are locally installed when you run npm install.

Thank you for checking it out. The problem turned out to be the NODE_PATH environment variable was set to a global yarn directory - which of course did not have tailwindcss installed…

Thanks for your help and support in the forums and github, etc - this is a great community. :slight_smile: