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

Syntax Error uncommenting a vite_rails template line #154

Closed
2 tasks done
mdesantis opened this issue Dec 12, 2021 · 1 comment · Fixed by #155
Closed
2 tasks done

Syntax Error uncommenting a vite_rails template line #154

mdesantis opened this issue Dec 12, 2021 · 1 comment · Fixed by #155
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified

Comments

@mdesantis
Copy link
Contributor

  • I have tried upgrading by running bundle update vite_ruby.
  • I have read the troubleshooting section before opening an issue.

Description 📖

The suggested code import.meta.globEager('./**/*_channel.js') raises the following syntax error:

Uncaught SyntaxError: unexpected token: ':'

I don't think Vite supports using import.meta.globEager without saving it in a variable, as the code above produces (with an asd_channel.js inside the entrypoints folder):

{ "./asd_channel.js": __glob_0_0,}

which is a syntax error without a variable declaration (i.e. const something = ) before.

Changing the code to something like const _ = import.meta.globEager('./**/*_channel.js') makes it work.

Reproduction 🐞

Please provide a link to a repo that can reproduce the problem you ran into.

I will if needed, but the error happens just uncommenting the line after installing vite_rails, so the repo may be useless.

Vite Ruby Info
bin/vite present?: true
vite_ruby: 3.0.3
vite_rails: 3.0.1
rails: 7.0.0.rc1
node: v14.17.5
npm: 8.0.0
yarn: 1.22.15
pnpm: 
ruby: ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]

installed packages:
rails-7-demo-vite-2@ /home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2
├─┬ vite-plugin-ruby@3.0.4
│ └── vite@2.7.1 deduped
└── vite@2.7.1
Output

Run DEBUG=vite-plugin-ruby:* bin/vite dev or DEBUG=vite-plugin-ruby:* bin/vite build and provide the output:

> DEBUG=vite-plugin-ruby:* bin/vite build
Building with Vite ⚡️
vite v2.7.1 building for production...
transforming...
✓ 2 modules transformed.
Unexpected token
file: /home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2/app/frontend/entrypoints/application.js:24:42
22: //
23: // // Import all channels.
24: import.meta.globEager('./**/*_channel.js')
                                              ^
25: //
26: // Turbolinks.start()
error during build:
Error: Unexpected token
    at error (/home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2/node_modules/rollup/dist/shared/rollup.js:158:30)
    at Module.error (/home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2/node_modules/rollup/dist/shared/rollup.js:12354:16)
    at Module.tryParse (/home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2/node_modules/rollup/dist/shared/rollup.js:12757:25)
    at Module.setSource (/home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2/node_modules/rollup/dist/shared/rollup.js:12660:24)
    at ModuleLoader.addModuleSource (/home/maurizio/Sviluppo/rails-7/rails-7-demo-vite-2/node_modules/rollup/dist/shared/rollup.js:22138:20)

Build with Vite failed! ❌

Screenshots 📷

Schermata del 2021-12-12 13-52-26

@mdesantis mdesantis added the bug: pending triage Something doesn't seem to be working, but hasn't been verified label Dec 12, 2021
mdesantis added a commit to mdesantis/vite_ruby that referenced this issue Dec 12, 2021
Fixes ElMassimo#154. It adds variable declaration to `import.meta.globEager`, as it seems that `Vite.js` doesn't support `import.meta.globEager` calls without saving them somewhere.
@ElMassimo
Copy link
Owner

That is a problem only if there's no semicolon on the previous line, so it's not a matter of whether Vite supports it or not.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants