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

Regression in compatibility with Tailwindcss #27056

Closed
Nautigsam opened this issue Nov 25, 2024 · 6 comments
Closed

Regression in compatibility with Tailwindcss #27056

Nautigsam opened this issue Nov 25, 2024 · 6 comments
Labels
invalid what appeared to be an issue with Deno wasn't

Comments

@Nautigsam
Copy link
Contributor

In version 2.0.6 I can run tailwind as such:

deno run -A npm:tailwindcss

After upgrading to 2.1.1 the same command fails:

error: Uncaught (in promise) ReferenceError: module is not defined                                                                                                         
module.exports = {                                                                   
^                                         
    at file:///home/project/tailwind.config.js:2:1
    at loadESMFromCJS (node:module:777:21)                                           
    at Module._compile (node:module:722:12)
    at loadMaybeCjs (node:module:770:10)                                                                                                                                   
    at Object.Module._extensions..js (node:module:755:12)                                                                                                                  
    at Module.load (node:module:662:32)                                              
    at Function.Module._load (node:module:534:12)                    
    at Module.require (node:module:681:19)                                           
    at require (node:module:812:16)       
    at file:///home/project/.cache/deno/npm/registry.npmjs.org/tailwindcss/3.4.1/lib/lib/load-config.js:46:27
                                                                                     
    info: Deno supports CommonJS modules in .cjs files, or when the closest
          package.json has a "type": "commonjs" option.           
    hint: Rewrite this module to ESM,                                                
          or change the file extension to .cjs,
          or add package.json next to the file with "type": "commonjs" option.                                                                                             
    docs: https://docs.deno.com/go/commonjs
@dsherret dsherret added the needs info needs further information to be properly triaged label Nov 25, 2024
@dsherret
Copy link
Member

I'm not able to reproduce this. Running deno run -A --reload npm:[email protected] runs successfully for me.

@Nautigsam
Copy link
Contributor Author

It works without arguments indeed, my bad. I did not include the arguments -i and -o in my report.

The full command I run is the following:

deno run -A --reload npm:[email protected] -i tailwind.css -o out.css

@dsherret
Copy link
Member

That also works.

@nathanwhit pointed out he can reproduce this when he has a tailwind.config.js with a module.exports = ... and that makes sense based on the error message.

So it's loading the tailwind.config.js, but that's defined as being ESM. There was a bug fix in Deno where we would incorrectly and accidentally identify the module kind (esm or cjs) based on the referrer (this is really bad to do for a lot of reasons I won't get into here). This file is probably defined in a spot that is considered ESM. You can fix this by changing module.exports = { to export default { in tailwind.config.js or if you have a package.json, you can tell Deno to treat .js files as possibly cjs in your Deno project by adding { "type": "commonjs" } to it.

@dsherret dsherret added invalid what appeared to be an issue with Deno wasn't and removed needs info needs further information to be properly triaged labels Nov 25, 2024
@dsherret
Copy link
Member

dsherret commented Nov 25, 2024

Also, sorry this bug fix caused a new error to appear, but Deno's behaviour is more correct now and will lead to less bugs/errors overall.

@Nautigsam
Copy link
Contributor Author

I confirm changing the config file to ESM works. Thank you!

@dsherret
Copy link
Member

Note I've opened #27094 which would tell Deno to attempt to load files as CJS even when there's not a "type": "commonjs" in the package.json (or even when there's not a package.json at all). This is opt-in because it makes module loading do more work and it could potentially break some applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid what appeared to be an issue with Deno wasn't
Projects
None yet
Development

No branches or pull requests

2 participants