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

precompile.js TypeError: name.replace is not a function #1295

Closed
nigelmegitt opened this issue Jul 7, 2020 · 2 comments
Closed

precompile.js TypeError: name.replace is not a function #1295

nigelmegitt opened this issue Jul 7, 2020 · 2 comments

Comments

@nigelmegitt
Copy link

nigelmegitt commented Jul 7, 2020

I'm getting a runtime error running precompile.js on line 114.

Command line:

$ node_modules/nunjucks/bin/precompile input_template.xml > output_template.js

gives a TypeError in the function _precompile when it tries to call:

  name = name.replace(/\\/g, '/');

Debugging, this is because further up the stack, in the precompile function, line 85, the call to _precompile passes in as the second argument opts.name || input. Whilst input is indeed my input filename string, opts.name is a function pointer, not a string. Replacing this text with opts.name() || input appears to fix the problem, though I'm not familiar enough with the codebase to understand if that is the right place to make the fix.

In my case opts.name() returns undefined, which means the input filename gets used instead.

nunjucks release 3.2.1
node v12.7.0

Stack trace:

  name = name.replace(/\\/g, '/');
              ^

TypeError: name.replace is not a function
    at _precompile (/XXX/node_modules/nunjucks/src/precompile.js:114:15)
    at precompile (/XXX/node_modules/nunjucks/src/precompile.js:85:22)
    at Object.<anonymous> (/XXX/node_modules/nunjucks/bin/precompile:45:13)
    at Module._compile (internal/modules/cjs/loader.js:777:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:840:10)
    at internal/main/run_main_module.js:17:11
nigelmegitt added a commit to nigelmegitt/nunjucks that referenced this issue Jul 7, 2020
Call `opts.name()` before testing if the result is undefined rather than passing the function pointer downstream.
@nigelmegitt nigelmegitt mentioned this issue Jul 7, 2020
4 tasks
nigelmegitt added a commit to nigelmegitt/nunjucks that referenced this issue Jul 7, 2020
nigelmegitt added a commit to bbc/ebu-tt-live-toolkit that referenced this issue Jul 7, 2020
@nigelmegitt
Copy link
Author

nigelmegitt commented Jul 7, 2020

Further digging: making the simple change I proposed did not work in #1296, because when the -name option is specified, opt.name is a string not a function pointer. This problem is absent in release 3.2.0, and was likely introduced by 93129bf when yargs was replaced with commander by @AlynxZhou and @fdintino - mentioning you here in case you can shed any further light on this, or fix the issue.

It seems to me that regardless of whether -name is specified on the command line or not, the value of opts.name should not end up being a function pointer: it should be undefined or a string.

@AlynxZhou
Copy link
Contributor

AlynxZhou commented Jul 8, 2020 via email

nigelmegitt added a commit to bbc/ebu-tt-live-toolkit that referenced this issue Jul 9, 2020
* Round decimal fractions more tidily, removing unnecessary trailing characters

* Move comments from ends of lines, no longer allowed in Cucumber

* Nicely format fontSize as well.

* Use nunjucks 3.2.0, revert when mozilla/nunjucks#1295 is fixed.

* Address review comment, use class parameter instead of hardcoded value
nigelmegitt added a commit to bbc/ebu-tt-live-toolkit that referenced this issue Aug 4, 2020
* Round decimal fractions more tidily, removing unnecessary trailing characters
* Move comments from ends of lines, no longer allowed in Cucumber
* Nicely format fontSize as well.
* Use nunjucks 3.2.0, revert when mozilla/nunjucks#1295 is fixed.
* Address review comment, use class parameter instead of hardcoded value
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.

2 participants