TypeError: Cannot read property "normalize" from undefined #221

Closed
swarnak opened this Issue Jul 5, 2012 · 8 comments

Projects

None yet

6 participants

@swarnak

I am using Rhino and requirejs for code optimization. Here is my main config

require.config({
    paths : {
        jquery: "http://localhost:8080/static/jquery/1.7.2/jquery.min",
        "jquery-ui": "http://localhost:8080/static/jquery-ui/1.8.20/js/jquery-ui.custom.min",
        underscore : "http://localhost:8080/static/underscore/1.3.3/underscore",
        backbone : "http://localhost:8080/static//backbone/0.9.2/backbone",
        text : "http://localhost:8080/static/require/2.0.2/js/plugins/text"
    },

    shim: {
        "underscore": {
            exports: '_'
        },

        "backbone": {
            deps: ['jquery','underscore'],
            exports: function(){
                return this.Backbone.noConflict();
            }
        },

        "jquery-ui": ['jquery']

    }
});

Here is the require optimizer config. I have used the empty:scheme for all the network resources.

({
    mainConfigFile: "../src/main/webapp/js/main.js",
    name: "main",
    preserveLicenseComments: false,
    out: "../src/main/webapp/js/optimized-main.js",
    paths: {
        jquery: "empty:",
        "underscore": "empty:",
        backbone: "empty:",
        "jquery-ui": "empty:",
        text: "empty:"
    },
    exclude: ["jquery","jquery-ui","backbone","underscore","text"]
})

the optimizer fails when it encounters the following file

define([
  'underscore',
  'jquery',
  'jquery-ui',
  'backbone',
  '../models/user',
  '../collections/navItems',
  '../collections/urlPatterns',
  'text!../../templates/menu.html'
], function(_, $, jqueryui, Backbone,User,NavItemsCollection, UrlPatternsCollection, menuTemplate){ .........
}

I get the following error
optimize:
[exec] [java] Tracing dependencies for: main
[exec] [java] Cannot optimize network URL, skipping: empty:.js
[exec] [java] TypeError: Cannot read property "normalize" from undefined
[exec] [java] In module tree:
[exec] [java] main
[exec] [java] app
[exec] [java] router
[exec] [java] views/desktop
[exec] [java] TypeError: Cannot read property "normalize" from undefined
[exec] [java] In module tree:
[exec] [java] main
[exec] [java] app
[exec] [java] router
[exec] [java] views/desktop
[exec] [java] Java Result: 1

the issue is occurring only due to the line 'text!../../templates/menu.html'

There are no issues when using relative paths. Why am I seeing this error? Is there some other config that can tell the build to ignore this dependency?

I am using requireJS 2.0.2 and r.js 2.0.2

@jrburke
requirejs member

The text plugin needs be loaded by the loader for it to process text! depenencies. Loader plugins are executed as part of a build to resolve their resources.

So it should be enough to remove the text: "empty:" from the paths config, and just leave the excludes: in so it is not included in the final build result. This assumes you have text.js available locally to be read by the optimizer.

@jrburke jrburke closed this Jul 6, 2012
@brettcave

i had this error with the text module. We pass jade templates and call Handlebars.compile on these templates to compile them into HTML. However, the optimizer tries to resolve the path to the jade template, and I can't figure out how to fix this. Here is some more info: http://stackoverflow.com/questions/14198686/optimizer-and-handlebars-client-side-jade-templates

@jrburke
requirejs member

In that example, the resource is specified as 'text!/templates/product/something.jade'. Since that path starts with a / it will be difficult to resolve in a build situation -- that resolves relative to the root of a server domain, which is difficult to translate to local file system lookups as used by the optimizer. Ideally the path to the template is made relative to that module. If the module is in the same directory as the templates directory, then 'text!/templates/product/something.jade' should be enough.

@byron633

Hi I am having a similar issue with the text plugin and optimization over Rhino. I'm running the optimization via Maven (have also been trying directly in ant) and each time I get the following error. If I remove the use of the text plugin from the file then optimization runs fine:

[artifact:mvn] [INFO] --- requirejs-maven-plugin:1.1.0:optimize (default) @ require-optimization-dependencies ---
[artifact:mvn] Tracing dependencies for: userauth/main
[artifact:mvn] Tracing dependencies for: control-panel/main
[artifact:mvn] [ERROR] C:\V11Source\GoldenEye\bin\requireOptimization\r.js#22427(eval):line 292:column 0:The choice of Java method java.lang.StringBuffer.append matching JavaScript argument types (null) is ambiguous; candidate methods are:
[artifact:mvn] interface java.lang.Appendable append(java.lang.CharSequence)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.StringBuffer)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.Object)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.String)
[artifact:mvn] class java.lang.StringBuffer append(char[])
[artifact:mvn] InternalError: The choice of Java method java.lang.StringBuffer.append matching JavaScript argument types (null) is ambiguous; candidate methods are:
[artifact:mvn] interface java.lang.Appendable append(java.lang.CharSequence)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.StringBuffer)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.Object)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.String)
[artifact:mvn] class java.lang.StringBuffer append(char[]) (C:\V11Source\GoldenEye\bin\requireOptimization\r.js#22427(eval)#292)
[artifact:mvn] In module tree:
[artifact:mvn] control-panel/main
[artifact:mvn] control-panel/module
[artifact:mvn] control-panel/usermenu/UsermenuCP
[artifact:mvn] InternalError: The choice of Java method java.lang.StringBuffer.append matching JavaScript argument types (null) is ambiguous; candidate methods are:
[artifact:mvn] interface java.lang.Appendable append(java.lang.CharSequence)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.StringBuffer)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.Object)
[artifact:mvn] class java.lang.AbstractStringBuilder append(java.lang.String)
[artifact:mvn] class java.lang.StringBuffer append(char[]) (C:\V11Source\GoldenEye\bin\requireOptimization\r.js#22427(eval)#292)
[artifact:mvn] In module tree:
[artifact:mvn] control-panel/main
[artifact:mvn] control-panel/module
[artifact:mvn] control-panel/usermenu/UsermenuCP

The define statement in UsermenuCP.js looks like:

define(['require', 'lib/jquery', 'lib/boilerplate/ViewTemplate', 'lib/require/text!control-panel/usermenu/UsermenuV.html',
'lib/require/text!control-panel/usermenu/UsermenuCP.css','userauth/CurrentUser', 'lib/boilerplate/helpers/Logger',
'lib/boilerplate/Context', 'lib/boilerplate/helpers/alertHandler','global/Labels'],

In my build file I have tried to exclude the text plugin but I still get the same issue. I've seen people with the same issue on the web but each time they fix it by moving to Node.js but that is not an option for us.

Sorry for all the text but for some reason I'm not able to upload images!

Any help would be very much appreciated

@jrburke
requirejs member

@byron633 if you put an if (line !== null) around the .append() call on this line:
https://github.com/requirejs/text/blob/master/text.js#L316

does that solve it? If so, then I'll do an update to the text plugin with that change.

@jbwyme

@byron633 @jrburke I was having the "Java method java.lang.StringBuffer.append matching JavaScript argument types (null) is ambiguous" issue as well and adding the null check seems have fixed it. A side note is that I'm also using the require-css plugin which is also missing a null check. Adding both checks in allowed the optimizer to complete successfully.

@alachab

i have the same issue can someone give us a EX to understand ???
Error: Error: ENOENT, no such file or directory '/home/adel.lachab/devel-optimizer/dist/js/ajax/getTemplate/user/workspaceHeader.tmpl'
In module tree:
main
controllers/user/main
views/user/workspace
views/user/header
text

@jrburke jrburke added a commit to requirejs/text that referenced this issue Jun 7, 2013
@jrburke jrburke Fixes issue mentioned in comments for requirejs/r.js#221 about Java u…
…sage
83a149b
@jrburke
requirejs member

@jbwyme I just pushed a text.js version 2.0.7 that has that line !== null change for the java case.

@alachab that sounds like the path issue: it was looking for a /home/adel.lachab/devel-optimizer/dist/js/ajax/getTemplate/user/workspaceHeader.tmpl but it did not exist. Perhaps a paths config was needed for the build config.

@busykai busykai added a commit to busykai/brackets that referenced this issue Nov 24, 2013
@busykai busykai Upgrade requirejs/text to 2.0.10
This version is required to load and run brackets properly on
node-webkit. See requirejs/text#55 for node-specific details.
Summary of changes:
  > rev to 2.0.10
  > Merge pull request #61 from AnSavvides/master
  > Merge pull request #60 from dakota/patch-1
  > rev to 2.0.9
  > Merge pull request #55 from busykai/master
  > Fixes #57 xpcshell: windows FileUtils.File does not like / paths
  > Rev version for 2.0.7
  > Fixes #52, handle non-existent files in node
  > Fixes issue mentioned in comments for requirejs/r.js#221 about Java usage
  > Merge pull request #49 from fsbdev/patch-1
c7764ea
@busykai busykai referenced this issue in adobe/brackets Nov 24, 2013
Merged

Upgrade requirejs/text to 2.0.10 #6103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment