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

[1.4.3.x] ecmascript >= 0.6.2 breaks bable-plugin-tcomb #8422

Closed
dj-foxxy opened this Issue Feb 24, 2017 · 21 comments

Comments

Projects
None yet
6 participants
@dj-foxxy

dj-foxxy commented Feb 24, 2017

Example repo

The babel-plugin-tcomb Babel plugin does not function correctly with Meteor
core package ecmascript after version 0.6.1.

We use flow, tcomb, and babel-plugin-tcomb for static and runtime
type-checking, respectively. In this example project, the echo function
in main.js should only be passed foo1 or foo2, as described by FooType
in FooType.js. The second call to echo passes an illegal argument, bar1
and we expect a tcomb generated TypeError.

Details

In this example project, the ecmascript packages is pinned to 0.6.1. Under
this version, the following code is generated for the FooType.js module.

module.export({
    FooType: function () {
        return FooType
    }
});

var _t; module.import('tcomb', {
    "default": function (v) { _t = v }
});

var FooType = _t.enums.of(['foo1', 'foo2'], 'FooType');

This code correctly exports tcomb's type checker for FooType and the misuse
of the echo function in main.js is correctly detected:

TypeError: [tcomb] Invalid value "bar1" supplied to foo: FooType (expected one of [
  "foo1",
  "foo2"
])

Updating the ecmascript package to version 0.6.2 creates the following code:

import _t from "tcomb";

var FooType = _t.enums.of(["foo1", "foo2"], "FooType");

Which causes a syntax error:

import _t from "tcomb";
^^^^^^

SyntaxError: Unexpected reserved word
    at Object.exports.runInThisContext (vm.js:53:16)

Adding babel-plugin-transform-es2015-modules-commonjs doesn't help:

$ meteor npm install --save-dev babel-plugin-transform-es2015-modules-commonjs

$ cat .babelrc
{
  "plugins": [
    "tcomb",
    "transform-es2015-modules-commonjs"
  ]
}

FooType is not exported:

"use strict";
var _tcomb = require("tcomb");
var _tcomb2 = _interopRequireDefault(_tcomb);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var FooType = _tcomb2.default.enums.of(["foo1", "foo2"], "FooType");

Question

Is there a fix for this issue or are we stuck with ecmascript@=0.6.1 (and
therefore release 1.4.2.7)?

Thanks,

Peter.

@abernix

This comment has been minimized.

Member

abernix commented Feb 24, 2017

Realistically, Meteor 1.4.2.7 should not be used with any version of ecmascript over 0.6.1 because of an incompatibility with the way that they process your code (see meteor/babel@c8815d2 for more information in the specific change).

Have you tried using Meteor 1.4.3.1 with ecmascript@0.6.3, which are compatible intended to be fully compatible with each other?

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Feb 24, 2017

Hi @abernix,

Thanks for the reply. I've tried v1.4.3.1 and v1.4.2.3 with ecmascript@=0.6.3 and the same problem occurs. We're actually using v1.4.2.3 with ecmascript@=0.6.1

It looks like being able to run the tcomb plugin before reify would solve the problem. Is that possible?

@abernix abernix changed the title from ecmascript >= 0.6.2 breaks bable-plugin-tcomb to [1.4.3.x] ecmascript >= 0.6.2 breaks bable-plugin-tcomb Feb 24, 2017

@abernix

This comment has been minimized.

Member

abernix commented Feb 24, 2017

Thanks for the easy reproduction repo. Much appreciated.

This is most likely because of meteor/babel@c8815d2. Unfortunately, changing the run order is not possible (and this change was made for good reasons) so you'll have to stick with Meteor <= 1.4.2.7 and ecmascript@=0.6.1 for the time being. I imagine a solution is possible though! 😉

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Feb 24, 2017

I don't really know enough about Meteor's use of Babel or Babel's itself. My guess is that I could fork the plugin and replace the parts where it inserts import statements with something that works with reify.

@billyvg

This comment has been minimized.

billyvg commented Feb 25, 2017

I'm having a different babel error, but I'm trying to use 1.4.2.7 with ecmascript@0.6.1, but it keeps upgrading ecmascript to 0.6.2.

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Feb 25, 2017

@billyvg I had that problem. You need to prefix the version with an =. I.e., ecmascript@=0.6.1.

@abernix abernix added this to the Release 1.4.3.x milestone Mar 3, 2017

@robertpitt

This comment has been minimized.

robertpitt commented Mar 7, 2017

Im having the same issue.

  • I have locked the meteor version to 1.4.2.7
  • I have locked the version of ecmascript to 0.6.1

The error I am getting is:

W20170307-01:47:03.744(0)? (STDERR) .meteor/local/build/programs/server/packages/biggerplate_frontend-react.js:40
W20170307-01:47:03.744(0)? (STDERR) import React from  'react';
W20170307-01:47:03.744(0)? (STDERR) ^^^^^^
W20170307-01:47:03.745(0)? (STDERR) 
W20170307-01:47:03.745(0)? (STDERR) SyntaxError: Unexpected reserved word
W20170307-01:47:03.745(0)? (STDERR)     at Object.exports.runInThisContext (vm.js:53:16)
W20170307-01:47:03.745(0)? (STDERR)     at .meteor/local/build/programs/server/boot.js:289:30
W20170307-01:47:03.746(0)? (STDERR)     at Array.forEach (native)
W20170307-01:47:03.746(0)? (STDERR)     at .meteor/local/build/programs/server/boot.js:128:5
W20170307-01:47:03.746(0)? (STDERR)     at .meteor/local/build/programs/server/boot.js:344:5
W20170307-01:47:03.747(0)? (STDERR)     at Function.run (.meteor/local/build/programs/server/profile.js:480:12)
W20170307-01:47:03.747(0)? (STDERR)     at .meteor/local/build/programs/server/boot.js:343:11

Versions File:

allow-deny@1.0.5
autoupdate@1.3.12
babel-compiler@6.14.1
babel-runtime@1.0.1
base64@1.0.10
biggerplate:frontend-react@0.0.1
binary-heap@1.0.10
blaze@2.3.0
blaze-tools@1.0.10
boilerplate-generator@1.0.11
caching-compiler@1.1.9
caching-html-compiler@1.1.0
callback-hook@1.0.10
check@1.2.5
ddp@1.2.5
ddp-client@1.3.3
ddp-common@1.2.8
ddp-server@1.3.12
deps@1.0.12
diff-sequence@1.0.7
ecmascript@0.6.1
ecmascript-runtime@0.3.15
ejson@1.0.13
geojson-utils@1.0.10
hot-code-push@1.0.4
html-tools@1.0.11
htmljs@1.0.11
http@1.2.10
id-map@1.0.9
jquery@1.11.10
jsx@0.2.4
livedata@1.0.18
logging@1.1.17
meteor@1.6.1
meteor-base@1.0.4
meteortoys:toggle@3.0.0
meteortoys:toykit@3.0.4
minifier-js@1.2.18
minimongo@1.0.19
modules@0.7.9
modules-runtime@0.7.9
mongo@1.1.14
mongo-id@1.0.6
msavin:mongol@2.0.1
npm-mongo@2.2.16_1
observe-sequence@1.0.15
ordered-dict@1.0.9
promise@0.8.8
random@1.0.10
react@0.1.0
react-meteor-data@0.1.9
react-runtime@0.13.3
react-runtime-dev@0.13.3
react-runtime-prod@0.13.3
reactive-dict@1.1.8
reactive-var@1.0.11
reload@1.1.11
retry@1.0.9
routepolicy@1.0.12
session@1.1.7
spacebars@1.0.13
spacebars-compiler@1.1.0
templating@1.3.0
templating-compiler@1.3.0
templating-runtime@1.3.0
templating-tools@1.1.0
tracker@1.1.2
ui@1.0.12
underscore@1.0.10
url@1.1.0
webapp@1.3.12
webapp-hashing@1.0.9

Release:

METEOR@1.4.2.7

Am I missing something?

@benjamn benjamn self-assigned this Mar 14, 2017

benjamn added a commit that referenced this issue Mar 14, 2017

Update meteor-babel to version 0.17.2.
The most important change in this version is that the Reify compiler is
now just another Babel plugin, so it's possible for other Babel presets
and plugins to run before it.

Fixes #8399.
Fixes #8422.
Fixes meteor/babel#13.
@benjamn

This comment has been minimized.

Member

benjamn commented Mar 17, 2017

This should be fixed if you run meteor update --release 1.4.3.3-beta.4 in your application directory. Now that Reify is just another Babel plugin, your custom plugins once again have a chance to run before the Reify compiler. Please feel free to reopen this issue if it's not resolved for you.

@benjamn benjamn closed this Mar 17, 2017

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 21, 2017

Edit: Just read related issues attempting after a reset.

Hi Ben. Thanks for the reply. Sadly simply running meteor update --release 1.4.3.3-beta.3 in the example repo does not change the issue. Do I have to edit my .babelrc to get my plugins to run first?

@abernix

This comment has been minimized.

Member

abernix commented Mar 21, 2017

@dj-foxxy Maybe try running meteor update --all-packages?

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 21, 2017

@abernix doesn't appear to help

$ meteor update --all-packages --allow-incompatible-update                                                                         
Not updating the release, because this app is at a newer release (METEOR@1.4.3.3-beta.3) than the latest recommended release (METEOR@1.4.3.2).
Your top-level dependencies are at their latest compatible versions.
                                              
The following top-level dependencies were not updated to the very latest version available:
 * ecmascript 0.7.0-beta.3 (0.8.0-beta.12 is available)
 * standard-minifier-js 2.0.0-beta.3 (2.0.0-beta.4 is available)
                                              
Newer versions of the following indirect dependencies are available:
 * babel-compiler 6.18.0-beta.3 (6.19.0-beta.12 is available)
 * minifier-js 2.0.0-beta.3 (2.0.0-beta.4 is available)
 * modules 0.8.0-beta.3 (0.9.0-beta.12 is available)
 * modules-runtime 0.8.0-beta.3 (0.8.0-beta.12 is available)
To update one or more of these packages, pass their names to 
`meteor update`, or just run `meteor update --all-packages`.
@abernix

This comment has been minimized.

Member

abernix commented Mar 21, 2017

@dj-foxxy Sorry, can you try meteor update --release 1.4.3.3-beta.4 (not .3)? I've updated @benjamn's comment above to use the more recent version to reflect the problems we discovered in #8423 (comment) (and the follow-up comments).

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 21, 2017

Thanks for the reply @abernix. Using beta.4 does translate the import statements as expected. However, nothing is actually exported from the module:

var _tcomb = require("tcomb");                                                                                   
var _tcomb2 = _interopRequireDefault(_tcomb);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var FooType = _tcomb2.default.enums.of(["foo1", "foo2"], "FooType");

FooType should be exported.

@benjamn

This comment has been minimized.

Member

benjamn commented Mar 21, 2017

@dj-foxxy What happens if you explicitly export FooType? The alternative is probably some significant debugging of the interactions between babel-plugin-tcomb and other Babel plugins, so I would recommend weighing that cost against the value of these invisible exports.

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 21, 2017

export FooType is a build errorL: FooType is just a Flow type until the tcomb plugin has run. The type is already exported, i.e., export type FooType = 'foo1' | 'foo2';. I had a similar probable when building knex from source. I had to add preset es2015 and the add-module-exports plugin, but that didn't help here.

@abernix abernix modified the milestones: Release 1.4.3.x, Release 1.4.3.3, Release 1.4.4 Mar 21, 2017

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 31, 2017

I can't reopen the issue because I don't have sufficient privileges but this issues is still not fixed. The export code is not generated as is used to be.

@abernix

This comment has been minimized.

Member

abernix commented Mar 31, 2017

@dj-foxxy Can you try again with Meteor 1.4.4-rc.5?

meteor update --release 1.4.4-rc.5

@abernix abernix reopened this Mar 31, 2017

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 31, 2017

Hi @abernix, thanks for getting back to me.

1.4.4-rc.5 generates the right code:

module.export({                                                      //
  FooType: function () {                                             //
    return FooType;                                                  //
  }                                                                  //
});                                                                  //
                                                                     //
var _t = void 0;                                                     //
                                                                     //
module.importSync("tcomb", {                                         //
  "default": function (v) {                                          //
    _t = v;                                                          //
  }                                                                  //
}, 0);                                                               //
                                                                     //
var FooType = _t.enums.of(["foo1", "foo2"], "FooType");              //
///////////////////////////////////////////////////////////////////////

But, I get another, probably unrelated error:

W20170331-10:58:49.925(1)? (STDERR) ReferenceError: dynamicImportInfo is not defined
W20170331-10:58:49.925(1)? (STDERR)     at meteorInstall.node_modules.meteor.dynamic-import.server.js (packages/dynamic-import/server.js:15:13
W20170331-10:58:49.925(1)? (STDERR)     at fileEvaluate (packages/modules-runtime.js:197:9)
W20170331-10:58:49.926(1)? (STDERR)     at require (packages/modules-runtime.js:120:16)
W20170331-10:58:49.926(1)? (STDERR)     at /home/foxxy/babel-plugin-tcomb-broken/.meteor/local/build/programs/server/packages/dynamic-import.j
:493:15
W20170331-10:58:49.926(1)? (STDERR)     at /home/foxxy/babel-plugin-tcomb-broken/.meteor/local/build/programs/server/packages/dynamic-import.j
:499:3
W20170331-10:58:49.926(1)? (STDERR)     at /home/foxxy/babel-plugin-tcomb-broken/.meteor/local/build/programs/server/boot.js:303:34
W20170331-10:58:49.926(1)? (STDERR)     at Array.forEach (native)
W20170331-10:58:49.926(1)? (STDERR)     at Function._.each._.forEach (/home/foxxy/.meteor/packages/meteor-tool/.1.4.4-rc.5.1ogzmv++os.linux.x8
_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20170331-10:58:49.926(1)? (STDERR)     at /home/foxxy/babel-plugin-tcomb-broken/.meteor/local/build/programs/server/boot.js:128:5
W20170331-10:58:49.926(1)? (STDERR)     at /home/foxxy/babel-plugin-tcomb-broken/.meteor/local/build/programs/server/boot.js:352:5

Also, 1.5-beta.13 works without a hitch.

@abernix

This comment has been minimized.

Member

abernix commented Mar 31, 2017

Are you trying to use the (Meteor 1.5-only) dynamic-imports package with Meteor 1.4.4? If so, that will absolutely not work. :)

@dj-foxxy

This comment has been minimized.

dj-foxxy commented Mar 31, 2017

Yer sorry. I tested 1.5 before 1.4.4 and forgot to do a git check --force so dynamic-imports was still in .meter/packages from the 1.5 upgrade. Tested on a clean checkout with 1.4.4 and everything works. Thanks for sorting this. Looks like 1.4.4 will be out soon so we'll upgrade to that in development and deploy once released.

@dedgar1

This comment has been minimized.

dedgar1 commented Jul 19, 2017

Dynamic-imports reappear each time I run the project. It doesn't mater how many times I delete the folder. Anything I can do to solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment