Src and node_modules transpiled differently


#1

Hi All

I have ben struggling with this issue, for some time and can t get my head around it.
What I basically want to do is use a repeat.for on a Map object. I expect this just to work, but I get a non-repeatable error. This repeat.for can be found in aurelia-template-resource package, and is is the instanceof keyword that does not work properly.
When I use instanceof in the codebehined of my aurelia components, it does work.

This makes me think the babel transpilation of my own source is different from the transpilation of the node_module before being squeezed into vendor-script.js

I synced the options in the babel config section of aurelia.json and .babelrc.

    {
  "sourceMap": true,
  "sourceRoot": "src",
  "moduleIds": false,
  "comments": false,
  "compact": false,
  "code": true,
  "presets": [
    ["es2015", {"loose": true}],
    "stage-1"
  ],
  "plugins": [
    "syntax-flow",
    "transform-runtime",
    "transform-decorators-legacy",
    "transform-flow-strip-types"
  ]
}

I use aurelia CLI 6.4.1 on Mac

Thanks for the help!

Wim


#2
  1. current cli version is 0.35.1, your v6.4.1 is probably your nodejs version. BTW, pls upgrade to latest nodejs v8.12.0, because next version of aurelia-cli will soon only works on v8.9.0+.

  2. don’t know whether you use webpack or requirejs. But in either way, please don’t touch the transpiler setting in aurelia.json. Transpilation is only for your local src, both webpack and requirejs setup skip node_module folder by default.

  3. are you following the doc on repeating Map object?
    https://aurelia.io/docs/templating/basics#repeaters

<p repeat.for="[greeting, friend] of friends">
  ${greeting}, ${friend.name}!
</p>

#3

Thanks for your reply!

  1. you are correct, I updated my node version
  2. I reset my aurelia.json changes. I dont really know what I use. Using the CLI I just use au build no clue what happens in the back. How do I know?
  3. This is exactly what I do. But when friends is a Map, it still uses the array-repeat-strategy instead of the map-repeat-strategy. This is caused by instanceof not working as expected…

Regards
Wim


#4
  1. you are probably using webpack as it’s the default, check you should have a webpack.config.js.

  2. how did you create your Map? friends = new Map(); is a Map object, friends = {} is not a Map object, it’s a plain JavaScript object. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map


#5

Hi

  1. I don’t have a webpack.config.js file, so it is requirejs right?

  2. I use the friends = new Map();

When I use gist.run or similar this just works, so I cannot reproduce it to show it.
I will try to create a new project and see if I can reproduce it.

Regards
Wim


#6

Sounds like an edge case bug, hope you can find a way to reproduce it.


#8

I did some more testing and I found out that somewhere down the line, the Map object is changed in an object. All the methods like Set are still available and working, however the instanceof returns object.
When I wrap it again into a Map (inside the vendor.js) it works again…