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

The Regex which is used to detect "import"-statements will detect import-statements within multiline-comments #1408

Closed
tobias74 opened this issue Aug 18, 2016 · 6 comments

Comments

@tobias74
Copy link

tobias74 commented Aug 18, 2016

var esmRegEx = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s*(\{|default|function|class|var|const|let|async\s+function))/;

This regex will detect statements like:
import { SomeThing } from "./myfile"

even in case they are wihtin a multiline-comment-block

/*
import { Something } from "./myfile"
*/

This behaviour can lead to very-hard-to-debug errors like these documented on Stackoverflow:

http://stackoverflow.com/questions/37179236/angular2-error-at-startup-of-the-app-http-localhost3000-traceur-404-not-fo/37181985#37181985

and

http://stackoverflow.com/questions/37022526/angular-2-404-traceur-not-found

EDIT:
Here a short description how this causes errors:

While working on a typescript-file wihtin an angular-project I commented out some lines of import-statements. The typescript-compiler then just copied these multiline-comments into the compiled js-files. When loading the app in the browser, systemjs would identify these import-statements in those comment-blocks and try to act on them. This leads to a hard-to-understand error-message: "404 traceur not found"

@guybedford
Copy link
Member

Yes this is the way module format detection works in SystemJS. I've added a more useful error message here in bac2cc5.

@RohitRane
Copy link

I am getting this error in the browser :
Unable to load transpiler to transpile http://localhost:8080/LKMonitoring/node_modules/@angular/http/index.js

But I don't see any block comments or import statements in this file!
Above all this is not even my code but core angular 2 library code.

How do I resolve this?

@fictitious
Copy link
Contributor

@RohitRane but there is export statement in that file, so it still needs to be transpiled. You probably need to use angular bundle for their http module which is in node_modules/@angular/http/bundles/http.umd.js

@zapping
Copy link

zapping commented Nov 18, 2016

I faced a similar issue with comments on the import section.
http://stackoverflow.com/questions/40677324/comments-in-angular2
angular/angular#12967

@rysilva
Copy link

rysilva commented Apr 11, 2018

This was a particularly nasty bug and cost me a few hours. It was due to block comments around 'export' lines. I guess since all of the tickets I've found related to this seem to be closed as roughly "working as designed" the best recourse is to use a different tool.

@guybedford
Copy link
Member

PRs are welcome to handle these edge cases better. Note that explicitly defining the module format for folders by meta configuration is encouraged as well.

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

6 participants