Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module - config file not found #137

Closed
mikecousins opened this issue Sep 11, 2018 · 9 comments
Closed

Cannot find module - config file not found #137

mikecousins opened this issue Sep 11, 2018 · 9 comments
Labels

Comments

@mikecousins
Copy link

mikecousins commented Sep 11, 2018

Describe the bug
When I try to run my build I'm getting an error that the config file can't be found.

To Reproduce
Steps to reproduce the behavior:

  1. Put a new script in your package.json: "purgecss": "purgecss -c purgecss.config.js -o src"
  2. Add purgecss.config.js file with the following contents: module.exports = { content: ['src/index.js'], css: ['src/tailwind.css'] }
  3. Type yarn run build
  4. See error message: Error: Error loading the config fileCannot find module '/C:\GitHub\repo/purgecss.config.js

Expected behavior
Build should happen with css purged

Desktop (please complete the following information):

  • OS: Windows 10
  • Version of Purgecss: 1.1.0

Additional context
This was raised on StackOverflow as well: https://stackoverflow.com/questions/51569213/purgecss-cli-c-cannot-find-module-purgecss-config-js/52277041

@jsnanigans
Copy link
Collaborator

jsnanigans commented Sep 11, 2018

thanks for reporting this, it looks like a bug on windows, in this path /C:\GitHub\repo/purgecss.config.js the last slash should be a backslash and i'm not sure if that first slash before C: should be there

@jsnanigans jsnanigans added the bug label Sep 11, 2018
@mikecousins
Copy link
Author

Agreed, that's what I commented on the StackOverflow bug too. Hopefully it's not too bad to fix.

@jsnanigans
Copy link
Collaborator

Ill have to first setup a VM with windows to test this but a possible workaround would be to just not use a config file and use purgecss programmatically. Create a purge_my_css.js file with something like this:

const Purgecss = require('purgecss')
const fs = require('fs')
const path = require('path')

const outputDir = path.resolve(__dirname, 'dist')

const purgecss = new Purgecss({
  content: ['src/*.html'],
  css: ['src/*.css']
})
const result = purgecss.purge()

result.forEach(out => {
	const filePath = out.file.split('/')
	fs.writeFileSync(`${outputDir}/${filePath[filePath.length - 1]}`, out.css, 'utf-8')
})

console.log('done')

then just run it with node purge_my_css.js

@alexqhj
Copy link

alexqhj commented Oct 24, 2018

I've fixed the issue on my end by simply replacing

var t = path.resolve(process.cwd(), pathConfig);
with
var t = path.join(process.cwd(), pathConfig);

I'm assuming since process.cwd() returns a fixed path, using join over resolve is a non-issue, but I'm not in the position to make PR's or tests at the moment.

Maybe someone else can research if this change would cause any issues?

@fabiopedrosa
Copy link

The fix from @alexqhj worked in my windows machine.

@Kravimir
Copy link

I finally got this to work by putting a symlink to the node_modules directory (named "node_modules") in each directory where I was running purgecss from.

@Wulfheart
Copy link

This problem still exists under windows.

@dev634
Copy link

dev634 commented Sep 27, 2019

image

i just changed it directly in the purgecss file

@dev634
Copy link

dev634 commented Sep 27, 2019

image

and apprently the developpers know the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants