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: TypeError: Cannot call method 'substring' of undefined at modLine #924

Closed
schirrel opened this issue Jul 28, 2016 · 8 comments
Closed

Comments

@schirrel
Copy link

I ran grunt at my project i got the error:

{ [Error: TypeError: Cannot call method 'substring' of undefined
at modLine (/myproject/node_modules/grunt-contrib-requirejs/node_modules/requirejs/bin/r.js:28040:48)
]
originalError: [TypeError: Cannot call method 'substring' of undefined] }

So i went and checked the line it is:

contentLines[lineIndex] = line.substring(0, startIndex) + contentInsertion + line.substring(startIndex, line.length);

inside the function modLine

I search but i didn't found any releated error.
:/

@jrburke
Copy link
Member

jrburke commented Jul 29, 2016

It is hard to know by just looking what state of the code would have caused this. If there is a test case that can be run to reproduce the issue, that would help.

@schirrel
Copy link
Author

HI, i solved it but, removing each extension of my project and add one by one to find the one with error...
Once i found the one who throw the error i tried to find in the class what was causing this....
And it was the comment line at the init of the fle

/*
* Created By .... 
*/

It is common to happen?

@jrburke
Copy link
Member

jrburke commented Jul 31, 2016

Comments should be fine. I expect the issue is with some hidden character in the file, that may mess up the parsing. If you have a copy of the file in question that you could attach to the issue, I can run some tests locally to see how it fails.

@AnirudhaGohokar
Copy link

Hey @jrburke,

I also faced the same issue.Removing the comments fixed the issue.
Please find the attached JS file that was causing the issue.
loginModule.js.txt

@jrburke jrburke added this to the 2.3.3 milestone Sep 26, 2016
@jrburke
Copy link
Member

jrburke commented Sep 26, 2016

Thank you for the test file. There is a fix in master for this, you can try the latest master snapshot to verify that it works for you:

https://raw.githubusercontent.com/requirejs/r.js/master/dist/r.js

@AnirudhaGohokar
Copy link

AnirudhaGohokar commented Sep 26, 2016

Hey jrburke,

Thanks for the fix. I have tried with latest snapshot and the files are getting optimized into a single file.
Though there's another issue related to this
i.e below unoptimized code when optimizing it into single file

/*jshint laxbreak:true */
define(function(){
    var createNController = function($scope,){..};
    return createNController;
}

is getting optimized as an anonymous module and the module path is getting randomly inserted inside the code:

define(function(){
    var createNController = function($scope){
         ...//some code here
         'modules/../createNController',[],//path getting randomly inserted inside code instead of inside define
};
    return createNController;
});

When I remove and add the /*jshint laxbreak:true */ comment back in the unoptimized file and run r.js optimizer again, its working correctly then.

Attaching the file with comment thats causing issues..
createNController.js.txt

@jrburke
Copy link
Member

jrburke commented Sep 27, 2016

I was trying to avoid doing work for this case, but I think I need to do some more work upfront, will reopen for examining a further fix, but it may not come until the weekend.

The core of the issue is the file containing just \r and not \r\n (or just \n if a unixy system). How are these files generated, why just the \r characters?

@jrburke jrburke reopened this Sep 27, 2016
@jrburke
Copy link
Member

jrburke commented Oct 1, 2016

The contentNController.js.txt file seems to have a mix of line endings: one with a \r\n, and the rest of the lines are \r. This is makes it difficult to determine how to parse on linebreaks. This seems to be a malformed file, and a file with just \r's in them also seems odd. This seems to break at least my expectations of windows using CRLF and unixy systems using just LF.

I'm going to reset the change I did, I need to understand more how these kinds of files are generated, and if it is better to get the problem fixed in whatever editor or process that is generating these files without the expected CRLF line returns. If anyone has details on this, feel free to add a comment here.

@jrburke jrburke removed this from the 2.3.3 milestone Oct 1, 2016
@jrburke jrburke closed this as completed in baf9d1d Oct 1, 2016
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

No branches or pull requests

3 participants