-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Version 2.1.2 Module parse failed: Unexpected token (2:2022) #124
Comments
Please give me enough details to reproduce this, what framework are you using, what is your ES target, what tools do yo use? Typescript? Javascript? What browser? What OS / Environment? The only thing I know by your question is that you're using selection-js somewhere :D To me this looks like that whatever you're using cannot process / parse the version I provide (ES6 / ES Modules). |
I created a very simple new node project just running the code in node and can reproduce the error. This is happening on our OSX machines and our jenkins build machines on CentOS. I'm pretty sure this is pretty reproducible. Let me know if you need more information. |
I'm getting the something similar when updating to 2.1.2. I had to revert back to 2.1.1. removeEventListener(t,e){
return this.t.get(t)?.delete(e),this
} Honestly the error is unclear, but I'm getting something similar while not using at all the same setup/loader. I try to make a Code Sandbox with a closer setup to mine, but the error didn't happen, though, making a sandbox of sirneb setup do trigger the bug : https://codesandbox.io/s/silent-dream-q7tee |
It's probably because of the optional-chaining. Try using babel-plugin-proposal-optional-chaining :) |
I'm seeing a similar issue using Nuxt.js: #125 |
@sirneb Make sure to use |
@simonwep my point wasn't to show that we can run this in node but that with a somewhat latest version of node, the javascript output has an syntax error. It sounds like the compiled javascript has optional chaining. I think this is the first time ES2020 specifications is used in selection.js. It is basically a breaking change, maybe not in most modern browsers but definitely some organization's development/build toolings (node version < 14). |
@sirneb Oh sorry, yeah this is intended :) I'll add a note about that in v3. It's always possible to transpile it down using the tool and target of your choice, from my side I'll provide a modern version which fits all needs 😊 |
The funny part is that I don't have babel in my module, I use React-script and Typescript 4.3.2. And I do use Optional chaining directly in my typescript code and it's working so I'm not sure why I get error from babel, but that might be because react-script do some magic in the build process. Anyway, I will look into that later. |
I'm seeing a similar error while compiling using Webpack in Electron. We have many optional chains elsewhere in our app and they work just fine. |
Could one of you please create a demo repository so that I can take a look into it? It's kinda weird that that many are having problems with it :( I'm not sure of how the setup of ya'll looks like. Maybe it's even a corrupt bundle but it's working perfectly on the demo page (in the browser as ES Module)... |
The beta for v3 is available - you may try it with this version or I'd take into consideration providing an unofficial legacy es5 bundle. |
I'm getting this error using the latest So I guess the steps to repro is:
@simonwep Could this be a bug from cra or some issue with the compiled esm/cjs file? |
Okay - this seems to be a problem with CRA, there are quite the amount of issues because of this:
The current workaround is this. Or just just a modern build tool such as vite 😄 |
That issue was solved with facebook/create-react-app#8526 and you just pasted the same issues twice 😛. The other issue is stale presumably because the current version is already |
Whoops - edited ^^ Yeah, guess that's the only way to use it with cra... I'll do that and ship an update later today. |
On second thought - I won't do this, at least not now, please bear with me. I came up with the following reasons, partially from my own experience with third-party libraries: Loss of performance and a bigger bundle-sizeYou can always transpile code down, but not the other way around (or that's very difficult to do). And since a lower ES Versions leads to a bigger bundle (+60% in my case) and much slower code (more statements) you can only lose by transpiling things down. Loss of control over how you bundle will look likeBy providing the (almost most) version of this library I give those who target ESNext browsers (like I do or generally users with modern bundlers) the chance to do the same with this library. Everybody else can explicitly specify what version they prefer by specifying the target in the bundler of their choice (as with CRA it's the package.json browserslist value). This way we all can achieve maximum efficiency when it comes to the bundle, and since I doubt that many will still have to target ES5 it wouldn't be a loss for those who target versions like ES6 or ES2017. If there are still issues with CRA I would encourage everyone to open an issue in the corresponding repository, it's time that builders catch up with today's standards :) But users still have the choice when you provide an ES5 version?!Yes but that's not necessarily a good thing. I've seen many just go for the ES5 version for the "greater browser support", and while that's true it's, especially for those who are new to this, less good since you don't know what you're actually shipping to the client. When working on a piece of software you normally know what kind of browsers / environments you're targeting. And many actually don't really care / are aware of the trade-offs these "legacy" files have. As noted above, by this I hope to encourage everyone to take a little bit more care of what they ship to the end-user (although by not doing something you normally don't help anyone but in this case, or for now, I'm going to do it - sorry for that). For example check out estimator.dev to see how much you could save (just on size) if you target a more modern browser. See also this web.dev post. A fix for the react package is published for v3.0.0-beta.7. I'm going to close this one as I would say that this is on purpose and you'll have to configure the tool you're using. |
We are seeing an "Unexpected token" error with version 2.1.2 (2.1.1 works fine) while compiling its dependencies.
We get a slightly more detailed error this inside our test suite while
SyntaxError: Unexpected token '.'
.I'm just reporting this as we are seeing it, I can dig into this more as we are reverting the version in our build for now.
The text was updated successfully, but these errors were encountered: