Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20346] Cant load certain NPM modules because of Syntax

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionWon't Fix
Resolution Date2016-02-10T04:45:59.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterCreative
AssigneeChris Barber
Created2015-12-29T08:17:21.000+0000
Updated2017-04-04T15:08:52.000+0000

Description

Lets take a practical example: we use mocha.js using npm, but as soon as we try to compile the project, it fails because of some JS syntax error in the tests directory of this module (for instance, I got an error like ' # is not a valid expression', or something related). My npm modules reside in app/lib/node_modules/.. so I can access them in my app. I have another node_modules in the root of my project, for modules like Grunt (since those didnt compile either because of the JS checking) and I dont need those in the runtime. Please do not suggest ti-mocha since that is not the issue here.

Comments

  1. Creative 2015-12-29

    error example:
       [ERROR] :  Error generating AST for "**somepath**/*.js"
       [ERROR] :  Unexpected character '#'
       [ERROR] :  line 1
       
  2. Sharif AbuDarda 2015-12-29

    Hello, If you don't actually show a simple test case (not your whole app) we can't run that exhibits the problem, the best anyone can do is make guesses. AST errors will generally tell you exactly what line and in what file they occur in. That should show you exactly where the error in your code is. Again, the best anyone can do is guess based on the single line of error log you provided and the fact that you haven't yet shared the full error output. So, Provide a sample test case which causing the error. Provide full platform information and component versions. Provide the full error log. And descrive the problem thoroughly. Thanks.
  3. Creative 2016-01-20

    Do you even read bug reports? Just make a js-file somewhere in your app directory so it gets compiled when you build the app. Make sure the file starts with
       #!/usr/bin/env node
       
    or some other expression with a pound/hash-symbol. Basically loading a specific NPM module causes the same issue since that just downloads a pack of js-files into your app. Although this is not valid javascript, a lot of npm modules use this notation for some unix reason. It cant be compiled by uglify. A solution here would be that you can ignore specific files by just copying them over instead of compiling them.
  4. Sharif AbuDarda 2016-01-21

    I tried your way. I created a js file with the name of "#test.js". I put it on the resource directory. The app compiles fine. No Error or exceptions. Tested with SDK 5.1.2.GA. Thanks.
  5. Creative 2016-02-04

    yes you dont read bug reports carefully. Now Try again with the line: TESTCASE (put this in any .js file on the 1st line for instance):
       #!/usr/bin/env node --expose_gc
       
    This is used in quite some npm modules and it prevents us from compiling. Thanks.
  6. Chris Barber 2016-02-10

    Titanium only supports standard JavaScript files. Files that begin with a shebang/hashbang are not standard JavaScript files. The shebang is a Unix-specific character sequence that is not supported by ECMAScript standard. We have no plans to support this. You will need to strip the shebang line, remove the .js extension, or remove the file altogether.
  7. Lee Morris 2017-03-23

    Closing ticket as Won't Fix with reference to the above comments.
  8. Creative 2017-04-04

  9. Chris Barber 2017-04-04

    [~uzbbert] Well, Uglify is only part of the problem. I reiterate my comment above. I will take a look at ALOY-1540.

JSON Source