Skip to content
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

Error with (options.includePaths || []).join is not a function #167

Closed
hectorleiva opened this issue Apr 25, 2016 · 2 comments · Fixed by #169
Closed

Error with (options.includePaths || []).join is not a function #167

hectorleiva opened this issue Apr 25, 2016 · 2 comments · Fixed by #169

Comments

@hectorleiva
Copy link

Hello,

This module has been great to me. I appreciate all the hard-work that has gone into it. I've been really happy with how it solves that email problem for my Node.js application.

I've been facing an issue when I began to update the versions of email-templates and node-sass to the latest versions as specified within the ReadMe: ^2.3.0 and ^3.5.3 respectively.

The issue lies in an edge-case where if I'm testing the .render method for the EmailModule repeatedly in a suite of tests. The first test will work, but on the second test, there will be a sort of "string collision" where for node-sass, instead of receiving an array, it receives a string that has been concat-ed and causing the following error:

error:  TypeError: (options.includePaths || []).join is not a function
    at getOptions (/this/node-project/node_modules/node-sass/lib/index.js:181:55)
    at Object.module.exports.render (/this/node-project/node_modules/node-sass/lib/index.js:268:13)
    at /this/node-project/node_modules/email-templates/lib/template-manager.js:126:10
    at renderSass (/this/node-project/node_modules/email-templates/lib/template-manager.js:124:10)
    at /this/node-project/node_modules/email-templates/lib/template-manager.js:63:22
From previous event:
    at render (/this/node-project/node_modules/email-templates/lib/template-manager.js:45:10)
    at renderFile (/this/node-project/node_modules/email-templates/lib/util.js:53:38)
    at /this/node-project/node_modules/email-templates/lib/email-template.js:200:38
From previous event:
    at EmailTemplate._renderStyle (/this/node-project/node_modules/email-templates/lib/email-template.js:188:14)
    at /this/node-project/node_modules/email-templates/lib/email-template.js:146:97
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
...

If I were to console.log what the value of options.includePaths is at line 180, it is the following:

1st iteration - 1st test

options.includePaths = [  '/this/node-project/app/templates/test-notification-email'  ];

2nd iteration - 2nd test

options.includePaths = "/this/node-project/app/templates/test-notification-email/this/node-project/app/templates/test-notification-email"

Note that on the second test, it isn't an array anymore, but a string that has concat-ed both strings of location of the template, thus resulting in the error of the .join() not working.

I'm honestly not entirely sure if it is on the node-email-templates end, or whether it is a node-sass issue - but I wanted to bring up. In either case, I'm going to be making sure that the versions I use are now static:

node-sass: 3.4.1
email-templates: 2.0.1

Those versions have worked for me on my suite of tests and the like. Below are all the specifications of which node versions I'm using and how it is implemented:

~$ node -v
v4.2.6
~$ npm -v
v2.14.12

~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

I wrote up the simplest test example that will demonstrate the issue, but to include all necessary files seems outside the scope of this Issue:

/* global describe, it, beforeEach */
/* jshint expr: true */
'use strict';

var chai = require('chai'),
  expect = chai.expect,
  path = require('path'),
  template_name = 'test-notification-email',
  EmailTemplate = require('email-templates').EmailTemplate;

chai.use(chaiAsPromised);

var mockData = {
  "title": "Mock Data Title",
  "body": "This is the body of the mock data object"
};

describe('Testing Render Methods', function() {
  beforeEach(function() {
    this.instance = EmailTemplate;
  });

  describe('Test one', function() {
    it('should render html', function(done) {
      var template_loc = path.join(__dirname, '/../', 'templates', template_name);
      var email_template = new this.instance(template_loc);

      email_template.render(mockData, function(err, rendered) {
        if (err) return;
        expect(rendered["html"]).to.not.be.empty;
        done();
      });
    });
  });

  describe('Test two', function() {
    it('should render html and not error out, but it will', function(done) {
      var template_loc = path.join(__dirname, '/../', 'templates', template_name);
      var email_template = new this.instance(template_loc);

      email_template.render(mockData, function(err, rendered) {
        if (err) return;
        expect(rendered["html"]).to.not.be.empty;
        done();
      });
    });
  });
});

If you've reached this far, thank you very much for your time and keep up the great work. :)

@row1
Copy link
Contributor

row1 commented May 2, 2016

I have the same issue. As a work around I am doing something like this:

javascript
function mockData() {
return {
"title": "Mock Data Title",
"body": "This is the body of the mock data object"
}
};

//
email_template.render(mockData(), function(err, rendered) {

@sunild
Copy link

sunild commented Jun 10, 2016

I had the same problem while using render() inside of gulp.watch(). Per @row1 's suggestion in #142 I used Object.assign() to work around the problem.

niftylettuce added a commit that referenced this issue Jul 7, 2016
Fixes #167 "join is not a function"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants