-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Error Unexpected token '{'
after upgrade [email protected] to [email protected]
#13863
Comments
Hello @mosofsky. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with |
I'm having this same issue in Safari 16.3 using StimulusJS and vite-rails. This typescript: export default class extends Controller {
static targets = ['menu']
} Is being turned into this: export default class extends Controller {
static {
this.targets = ["menu"];
}
} And Safari says |
I recently upgraded from 4.3.0 to 4.4.4. After doing a few downgrades, 4.3.9 works fine, but 4.4.0 produces this error. |
We're getting this error as well, only in Safari 15 and earlier (in our Astro + Vue app). @mosofsky would you mind updating the title of this issue, since it's not just about Cypress? It affects production applications. |
@ffxsam are you also using Typescript? |
@natematykiewicz Yessir. |
https://github.com/evanw/esbuild/blob/main/CHANGELOG.md#0180 I think this is the real problem: But I can't figure out the right way to set the esbuild target via Vite. |
Under Vite 4.3.9 this Typescript becomes this: export default class dropdown_menu_controller_default extends Controller {
}
dropdown_menu_controller_default.targets = ["menu"]; |
What's your build target in tsconfig.json? Ours is es2015, and I'm assuming we're no longer getting es2015 with the esbuild 0.18 upgrade. |
Since we have to support Safari (probably as early as version 12 or 13—ugh), our target is es2015 as well. We also import |
Unexpected token '{'
after upgrade [email protected] to [email protected]Unexpected token '{'
after upgrade [email protected] to [email protected]
Can someone help provide a repro for this? I made a stackblitz, but I can't quite repro the difference between Vite 4.3.9 and 4.4.0. Couple questions:
I think I have a fix, but I'm not sure what regression it's fixing. Also related #13756
As noted in #13525:
Which I can also confirm, that I'm not sure if we have a regression here. |
So far I've been unable to put together a reproduction from scratch. So I think I'm gonna work the other way around: take my project, make a branch, and start cutting chunks away until the problem goes away. Then I'll have a better idea of how to create a reproduction—hopefully. |
{
"compilerOptions": {
"target": "es2015",
"lib": [
"dom",
"dom.iterable",
"es2015"
],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"noEmit": true,
"module": "esnext",
"sourceMap": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"noUnusedLocals": true,
"types": [
"vite/client"
]
},
"include": [
"app/javascript/**/*.ts",
"vite.config.ts"
],
"exclude": [
"node_modules"
]
}
import { defineConfig } from 'vite'
import RubyPlugin from 'vite-plugin-ruby'
export default defineConfig({
plugins: [RubyPlugin()],
})
|
Re-opening since there seems to be a regression somewhere, but I'm still unsure how it happens. @natematykiewicz Thanks for the response. IIUC the |
Changing the compiler options target on 4.3.9 is definitely changing my output JS. Given this typescript: import { Controller } from '@hotwired/stimulus'
import { useClickOutside } from 'stimulus-use'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { enter, leave } from 'el-transition'
export default class extends Controller {
static targets = ['menu']
declare menuTarget: HTMLElement
connect() {
useClickOutside(this, { element: this.menuTarget })
}
show() {
this.menuTarget.classList.remove('hidden')
enter(this.menuTarget)
}
hide() {
Promise.all([leave(this.menuTarget)]).then(() => {
this.menuTarget.classList.add('hidden')
})
}
toggle() {
if (this.menuTarget.classList.contains('hidden')) {
this.show()
} else {
this.hide()
}
}
clickOutside() {
this.hide()
}
} And this section of tsconfig.json: {
"compilerOptions": {
"target": "es2015",
}
} es2015 import { Controller } from "/vite-dev/@fs/.../node_modules/.vite/deps/@hotwired_stimulus.js?v=11d7a1aa";
import { useClickOutside } from "/vite-dev/@fs/.../node_modules/.vite/deps/stimulus-use.js?v=11d7a1aa";
import { enter, leave } from "/vite-dev/@fs/.../node_modules/.vite/deps/el-transition.js?v=11d7a1aa";
export default class dropdown_menu_controller_default extends Controller {
connect()
{
useClickOutside(this, {
element: this.menuTarget
});
}
show()
{
this.menuTarget.classList.remove("hidden");
enter(this.menuTarget);
}
hide()
{
Promise.all([leave(this.menuTarget)]).then(() => {
this.menuTarget.classList.add("hidden");
});
}
toggle()
{
if (this.menuTarget.classList.contains("hidden")) {
this.show();
} else {
this.hide();
}
}
clickOutside()
{
this.hide();
}
}
dropdown_menu_controller_default.targets = ["menu"]; esnext import { Controller } from "/vite-dev/@fs/.../node_modules/.vite/deps/@hotwired_stimulus.js?v=11d7a1aa";
import { useClickOutside } from "/vite-dev/@fs/.../node_modules/.vite/deps/stimulus-use.js?v=11d7a1aa";
import { enter, leave } from "/vite-dev/@fs/.../node_modules/.vite/deps/el-transition.js?v=11d7a1aa";
export default class extends Controller {
static targets = ["menu"];
connect() {
useClickOutside(this, { element: this.menuTarget });
}
show() {
this.menuTarget.classList.remove("hidden");
enter(this.menuTarget);
}
hide() {
Promise.all([leave(this.menuTarget)]).then(() => {
this.menuTarget.classList.add("hidden");
});
}
toggle() {
if (this.menuTarget.classList.contains("hidden")) {
this.show();
} else {
this.hide();
}
}
clickOutside() {
this.hide();
}
} Omitting the compilerOptions: import { Controller } from "/vite-dev/@fs/.../node_modules/.vite/deps/@hotwired_stimulus.js?v=11d7a1aa";
import { useClickOutside } from "/vite-dev/@fs/.../node_modules/.vite/deps/stimulus-use.js?v=11d7a1aa";
import { enter, leave } from "/vite-dev/@fs/.../node_modules/.vite/deps/el-transition.js?v=11d7a1aa";
export default class dropdown_menu_controller_default extends Controller {
connect()
{
useClickOutside(this, {
element: this.menuTarget
});
}
show()
{
this.menuTarget.classList.remove("hidden");
enter(this.menuTarget);
}
hide()
{
Promise.all([leave(this.menuTarget)]).then(() => {
this.menuTarget.classList.add("hidden");
});
}
toggle()
{
if (this.menuTarget.classList.contains("hidden")) {
this.show();
} else {
this.hide();
}
}
clickOutside()
{
this.hide();
}
}
dropdown_menu_controller_default.targets = ["menu"]; It's worth noting, every time I change my tsconfig.json while my server is running, I see this log line:
On Vite 4.4.7, with "es2015" the file is: import { Controller } from "/vite-dev/@fs/.../node_modules/.vite/deps/@hotwired_stimulus.js?v=c8bdaac7";
import { useClickOutside } from "/vite-dev/@fs/.../node_modules/.vite/deps/stimulus-use.js?v=24b8e4a2";
import { enter, leave } from "/vite-dev/@fs/.../node_modules/.vite/deps/el-transition.js?v=b7575016";
export default class extends Controller {
static {
this.targets = ["menu"];
}
connect() {
useClickOutside(this, { element: this.menuTarget });
}
show() {
this.menuTarget.classList.remove("hidden");
enter(this.menuTarget);
}
hide() {
Promise.all([leave(this.menuTarget)]).then(() => {
this.menuTarget.classList.add("hidden");
});
}
toggle() {
if (this.menuTarget.classList.contains("hidden")) {
this.show();
} else {
this.hide();
}
}
clickOutside() {
this.hide();
}
} This errors. Safari does not seem to understand this part: static {
} I tried "esnext" and the file is: import { Controller } from "/vite-dev/@fs/.../node_modules/.vite/deps/@hotwired_stimulus.js?v=a996cf86";
import { useClickOutside } from "/vite-dev/@fs/.../node_modules/.vite/deps/stimulus-use.js?v=a996cf86";
import { enter, leave } from "/vite-dev/@fs/.../node_modules/.vite/deps/el-transition.js?v=a996cf86";
export default class extends Controller {
static targets = ["menu"];
connect() {
useClickOutside(this, { element: this.menuTarget });
}
show() {
this.menuTarget.classList.remove("hidden");
enter(this.menuTarget);
}
hide() {
Promise.all([leave(this.menuTarget)]).then(() => {
this.menuTarget.classList.add("hidden");
});
}
toggle() {
if (this.menuTarget.classList.contains("hidden")) {
this.show();
} else {
this.hide();
}
}
clickOutside() {
this.hide();
}
} I tried a bunch of different values for compilerOptions target, and es2021 errors (same output as es2015), but es2022 works fine (same output as esnext). This is so strange. I'm sure it's obvious, but by updating Vite from 4.3 to 4.4, it also updated esbuild from 0.17 to 0.18. |
I've found the bug and opened #13992 to fix it. It was But it is still true that the |
@bluwy Awesome, thank you for the fix!! About Thanks! |
@ffxsam I've touched on that at #13756 (comment). Maybe in future versions |
@bluwy Gotcha. It's strange, we're not specifying |
Yeah it'd be better to resort to the Vite configuration whenever possible, I'm not sure how it's picking up that |
I was able to upgrade from 4.3.9 to 4.4.8 without any problems. So it looks like you fixed whatever was happening. Thanks! I agree with ffxsam. I feel like I'm not configuring something right. I'm not setting any targets in my Vite config, but when I had tried, they didn't seem to help my problem. |
I just tried
These errors look like they're coming from third-party libraries, so I have no control over this. |
Describe the bug
I tried to upgrade [email protected] to [email protected] but Cypress could not longer run tests because of the error
Unexpected token '{'
(see logs section for more detailed stack trace).Reproduction
sorry none at this time
Steps to reproduce
I will write more detailed steps to reproduce if this upgrade becomes more important.
I suspect the following would work:
yarn add [email protected]
(note, I'm stuck on this old Cypress version)System Info
Used Package Manager
yarn
Logs
Vite Logs
See google doc, it was too long to paste into the message body.
Cypress Console Log
Error seen in Cypress console:
More detail by printing the Cypress log to the console log:
Validations
The text was updated successfully, but these errors were encountered: