-
Notifications
You must be signed in to change notification settings - Fork 639
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
Class constructor Model cannot be invoked without 'new' #388
Comments
EDIT: Yep, please read the change log. Legacy node versions (0.10, 0.12) are no longer supported. You also need to migrate from the legacy ES5 inheritance to class Model {
}
function UserModel() {
// You cannot do this.
Model.apply(this, arguments);
} And since objection Check out the ESNext example project as an example of how to setup babel. |
Thanks. I did look at the changelog, maybe you should be more explicit about Babel. I have shared code between backend and frontend, guess I'll have to do some refactoring before I can upgrade to |
You're right, I'll add a mention about Babel & friends to the change log. I'll also leave this open for other people to find. |
You can also make it so that babel is using your node version by doing something like this:
|
@juhaelee Awesome, didn't know about that! Do you happen to know which Babel versions support that? |
@koskimas I believe you can use it as long as you're using Babel 6. You just need to use the |
I think this can be closed now that most people have migrated to objection 0.7. |
I'm using
this means babel compiles my code on the fly, except for things being imported from my build/node_modules folder. However, it turns out that objection does not compile into something es6+ compatible, so writing something like Changing the babel config to ignore
As I learned from this comment (and the ones below) My versions: |
@jnelken I don't know if I misunderstood something, but you don't need to transpile objection! The problem is not objection code but the way babel emulates classes in ES5. What you need to do is to turn off the class emulation since node 7.5 fully supports native classes. You don't need that emulation. That's what the |
@koskimas Ok, so it seems the |
Hi, I'm trying to use objection.js in a next.js project but am also running into this problem with It probably has something to do with their babel preset Looks like this is the preset: https://github.com/zeit/next.js/blob/canary/server/build/babel/preset.js |
I'm not that familiar with For me, I had to execute |
Ran into this too. Objection should export ES5 code (perhaps something like |
World should be ready for ES6 classes by now. We will not add support for ES5. |
I am trying to use objection.js with Node in AWS Lambda (Node 8.10). I struggled for a few hours until I hit the jackpot. I tried several configuration recommendations and what finally did the trick was excluding the Cheers! // webpack.config.js
...
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
target: { node: '8.10' }, // Node version on AWS Lambda
modules: false,
exclude: ['babel-plugin-transform-classes'],
},
],
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-runtime',
],
},
},
},
... |
Just in case it helps anyone, I had a lot of trouble with There is an |
If using TypeScript compiler, set output to at least {
"compilerOptions": {
"target": "es2015"
}
} |
I'm facing the same issue with Next.js. We use a single I agree with @vjpr, I think that it would be simpler to publish a ES5 code in the npm package. I'm gonna start looking for a solution now. |
1 hour later, my solution: babelrc.js const node = [`${__dirname}/src/api`]
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
ie: 11,
edge: 14,
firefox: 45,
chrome: 49,
safari: 10,
node: '6.11',
},
},
],
],
overrides: [
{
test: filename => node.some(prefix => filename.startsWith(prefix)),
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
},
],
} |
Having the same issue. Cannot for the life of me get it to work. EDIT: It was my .browserslistrc that caused the error as noted by @inversion above.
|
@koskimas After all the reports, don't you think its worth transpiling it? I don't think the world is ready just yet. Most people run their code through babel, and its tricky to ignore one file from transpilation. It also entails having to ignore all the files that touch objection. Objection is the only lib in my stack that I need this complicated workaround for right now. |
@vjpr Don't know your environment, but @inversion had a fix that worked for me, the error was unrelated to objection. |
@vjpr No I don't think we should transpile objection. You should open issues in whatever project is preventing you from using libraries that use the |
I've tried babel transpilation for about a year but mainly do server-side dev and was pretty unpleased with the results.. until the ECMAScript guys can solve their (several year) battle of At any rate, classes are supported in most modern browsers: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes So perhaps I'm missing something here - but the majority of your babel issues seem to stem from mis-configurations. |
Yeah this is difficult. My JS environment is pretty crazy because I'm using Razzle for server-side rendering of a React app, and I use Because I'm using Razzle, I don't have full access to my full webpack+babel config. Even if I could edit my config, it would feel hacky to carve out an exception for objection. Long story short, I found it easier to fork and compile
|
@ericvicenti I ended up doing something similar, thanks for the idea
compiled using |
This definitely helped me... |
This is so painful. I don't know any other library that is using untranspiled ES6 classes that you inherit from. Using babel overrides is really frustrating, and every new environment has to deal with it. E.g. Ava test babel config, Wallaby test babel config, webpack config, and project babel config. There are so many issues open about this and |
👍
On Fri, 18 Jan 2019 at 17:47, Sami Koskimäki <notifications@github.com>
wrote:
@vjpr <https://github.com/vjpr> Please use some other library then.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARLRanODl0RXag6yy6Uqh6ExX_t_ST8ks5vEfqEgaJpZM4Nj8wd>
.
|
@vjpr if babel is giving you so much problems, why are you using it? Even node 6 LTS is going out of maintenance in April (if I remember correctly), so I don't see why babel targetting es5 is so necessary... 🤔 Other thing you could do is to provide your own transpiled objection version available. |
@vjpr Could you try out this commit in your |
@vjpr This commit removes the need to |
@ericvicenti @thenanyu Could you also try pointing your package.json to this commit to see if it works with your setups without adding any special cases for objection? |
also @Malouda ⬆️ |
@vjpr I can release an RC version right now, but I want to run some additional tests before releasing 1.5.0 (I've rewritten the |
You can install the RC version using |
Oh crap, some tests are broken because of this and I also need to wrap other classes. I'll probably release the next RC during the next week. |
1.5.0-rc.5 is now released with the fix. |
And now the official 1.5.0 is released. No need for |
I'm getting the following error after upgrading to
0.8.0
:The text was updated successfully, but these errors were encountered: