EmranMR / tree-sitter-blade

tree-sitter grammar for Laravel blade files
MIT License
199 stars 8 forks source link

Error during "tree-sitter generate" #70

Closed klimeryk closed 2 months ago

klimeryk commented 2 months ago

I've been following https://github.com/EmranMR/tree-sitter-blade/discussions/19 to set up this project in NeoVim. However, when running :TSInstall blade, I'm getting the following error:

nvim-treesitter[blade]: Error during "tree-sitter generate"                                                                                                                         
file:///Users/klimeryk/.local/share/nvim/tree-sitter-blade/grammar.js:1                                                                                                             
module.exports = grammar({                                                                                                                                                          
^                                                                                                                                                                                   

ReferenceError: module is not defined in ES module scope                                                                                                                            
This file is being treated as an ES module because it has a '.js' file extension and '/Users/klimeryk/.local/share/nvim/tree-sitter-blade/package.json' contains "type": "module". T
o treat it as a CommonJS script, rename it to use the '.cjs' file extension.                                                                                                        
    at file:///Users/klimeryk/.local/share/nvim/tree-sitter-blade/grammar.js:1:1                                                                                                    
    at ModuleJob.run (node:internal/modules/esm/module_job:234:25)                                                                                                                  
    at async ModuleLoader.import (node:internal/modules/esm/loader:473:24)                                                                                                          
    at async file:///Users/klimeryk/.local/share/nvim/tree-sitter-blade/[eval1]:489:16                                                                                              

Node.js v20.17.0                                                                                                                                                                    
Failed to load grammar.js                                                                                                                                                           

Caused by:                                                                                                                                                                          
    node process exited with status 1  

Looking at recent changes, seems that https://github.com/EmranMR/tree-sitter-blade/commit/5eae5e1677191bb42506bf160906e34612a438b0 might have caused this? Removing type: module from package.json indeed allowed me to install it successfully (https://github.com/klimeryk/tree-sitter-blade/commit/6d0cb7902db63daf694dd2c74a8e1da772114feb). But I'm not sure if that's the ideal fix, depending on if you do want it as ES module or not.

cdarken commented 2 months ago

This fix works for me too. Maybe a pull request would be in order.

EmranMR commented 2 months ago

Hi all, sorry for the delay and the inconvenience this has caused. This was due to the ESLint's recent migration from commonJS to ES module!

Please pull the new commit and it should work fine now :).

cdarken commented 2 months ago

@EmranMR have you tried your fix? It won't install. This is the error for me:

nvim-treesitter[blade]: Error during "tree-sitter generate"                                                                     
No such file or directory (os error 2)
EmranMR commented 2 months ago

@cdarken Mmm you are right, let me give it another shot, the issue is if I remove module from package.json it messes with the CI, and the tree-sitter and its dependencies are all commonJS unfortunately... :/ . I am just going to remove CI action for now, until I figure this out!

It should work again this time for sure! 😅.

klimeryk commented 2 months ago

Thanks for the fix - confirmed it's working now again 🙇