I got burned a few days ago while trying to do a sync() on my database and getting the error SyntaxError: Unexpected token = originating within lodash's .template function. It turns out and some other module in my project is altering lodash's global templateSettings.interpolate value and since Sequelize is utilizing the global lodash object it was wasn't able to parse templates with the default interpolate regex. I know this is the other library's fault at the end of the day but wouldn't it make sense within Sequelize to either pass default options to each call of .template(text, data, [options]) or perhaps instantiate a separate lodash object to Util._ instead of using the global singleton?
The text was updated successfully, but these errors were encountered:
Well, not exactly. I'm using the same version of lodash in my project alongside Sequelize which is what ends up populating Utils._ when Sequelize requires it in utils.js. This project-level lodash also gets required in the other module that is overwriting _.templateSettings values which subsequently causes Sequelize to error out when using _.template. Does that make sense?
To test this you can create a project that depends on both lodash and Sequelize. After npm install you'll notice that node_modules/sequelize/node_modules does not contain a lodash directory. So if you do something like require('lodash').templateSettings.interpolate = 123 then require('sequelize').Utils._.templateSettings.interpolate will equal 123 and all Utils._.template calls will fail. It's a side-effect of node's module caching and npm's merging of identical dependencies.
@janmeier@mickhansen This has nothing to do with sequelize and it would be best to fix the issue in the library that alters the the function. So I would close this issue. @dizlexik Would be so kind and open an issue in the problematic library? Because this is bad for all librarys that depend on the lodash function.