Hello @FGRibreau ! I'm working on migrating mjml-chart to use mjml 4. I was hoping it would be pretty easy but I'm stuck at the moment:
Here’s a log of everything I've done so far to migrate mjml-chart to mjml 4.
Fork and clone repo.
Install dependences with npm i - no issues (as long as you're using node v8.10.0)
Tested everything by running npm test - all tests pass
Update mjml-core and mjml-image to v4.0.5. Then run npm test
This produces an error stating that:
(TypeError: (0 , _mjmlCore.MJMLElement) is not a function
So next thing I did was look at mjml-core to see what changed. Based on how they create components in MJML v4 (here's an example, it looks like they use a class called 'BodyComponent' instead of 'MJMLElement'.
Edit scripts/templates/component.js.tmpl and lib/index.js to use 'BodyComponent'
//Inside index.js
var Chart = (0, _mjmlCore.BodyComponent)(_class = function (_Component) {
Run npm test again. Still get the same error. This time it's coming from the file in src/index.js, which you say not to edit directly because it's generated with npm run update. From this comment, I would assume I can run npm run update but there is no script in the package.json. However, there is a script called "generate" which looks like will generate a new file of the component which may fix the test.
Run npm run generate then run npm test. This is looking better. There is a DeprecationWarning from Mocha. Following the link, we learn that we can add --no-deprecation too remove this warning. So add that to the following scripts:
"test"
"test-watch"
Run npm test again. 0 tests past. We see this error: TypeError: (0 , _mjmlCore.registerMJElement) is not a function - looks like this was changed in v4. Based on the current version, looks like this method changed to registerComponent so chagne that inside test/mjml-chart.spec.js
Run npm test. Now we see 0/5 tests passing. The common error is _mjmlCore.MJMLRenderer is not a constructor. Looking at the current version, I believe this has been moved into a separate package called [mjml-validator`](https://www.npmjs.com/package/mjml-validator) so I install that as a dev-dependency.
Run npm test again. Now the error we get is:
TypeError: Cannot read property 'undefined' of undefined
at validateAttribute (node_modules/mjml-validator/lib/rules/validAttributes.js:38:29)
My guess is that it is trying to validate the attributes for mjml-chart but doesn't know where to look
for the list of valid attributes? I'm a little stuck here. Not sure where to debug or how to solve this.
Hello @FGRibreau ! I'm working on migrating mjml-chart to use mjml 4. I was hoping it would be pretty easy but I'm stuck at the moment:
Here’s a log of everything I've done so far to migrate mjml-chart to mjml 4.
Fork and clone repo.
Install dependences with
npm i
- no issues (as long as you're using node v8.10.0)Tested everything by running
npm test
- all tests passUpdate
mjml-core
andmjml-image
to v4.0.5. Then runnpm test
(TypeError: (0 , _mjmlCore.MJMLElement) is not a function
So next thing I did was look atmjml-core
to see what changed. Based on how they create components in MJML v4 (here's an example, it looks like they use a class called 'BodyComponent' instead of 'MJMLElement'.Edit
scripts/templates/component.js.tmpl
andlib/index.js
to use 'BodyComponent'//Inside index.js var Chart = (0, _mjmlCore.BodyComponent)(_class = function (_Component) {
Run
npm test
again. Still get the same error. This time it's coming from the file insrc/index.js
, which you say not to edit directly because it's generated withnpm run update
. From this comment, I would assume I can runnpm run update
but there is no script in the package.json. However, there is a script called "generate" which looks like will generate a new file of the component which may fix the test.Run
npm run generate
then runnpm test
. This is looking better. There is a DeprecationWarning from Mocha. Following the link, we learn that we can add--no-deprecation
too remove this warning. So add that to the following scripts:Run
npm test
again. 0 tests past. We see this error:TypeError: (0 , _mjmlCore.registerMJElement) is not a function
- looks like this was changed in v4. Based on the current version, looks like this method changed toregisterComponent
so chagne that insidetest/mjml-chart.spec.js
Run
npm test
. Now we see 0/5 tests passing. The common error is_mjmlCore.MJMLRenderer
is not a constructor. Looking at the current version, I believe this has been moved into a separate package called [
mjml-validator`](https://www.npmjs.com/package/mjml-validator) so I install that as a dev-dependency.Run
npm test
again. Now the error we get is:My guess is that it is trying to validate the attributes for mjml-chart but doesn't know where to look for the list of valid attributes? I'm a little stuck here. Not sure where to debug or how to solve this.