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

R.js - Path must be a string #231

Open
JohnRSim opened this issue May 18, 2017 · 4 comments
Open

R.js - Path must be a string #231

JohnRSim opened this issue May 18, 2017 · 4 comments

Comments

@JohnRSim
Copy link

JohnRSim commented May 18, 2017

When optimising the css with r.js i'm getting the following error below?

sample module --

define(
    [
        'Action',
        'SPA_css!./adminPanel'
    ],
    function (Action) {

exampe config

{
                optimize: 'none',//'uglify',
				preserveLicenseComments: false,
                useStrict: true,
			    paths: {
					hgn: 				'../../lib/requirejs/hgn',
					hogan: 				'../../lib/requirejs/hogan',
	        		text: 				'../../lib/requirejs/text',
					Action:'empty:',
					//css:'empty',
					css: 			'empty:',
					normalize:'empty:',
					SPA_css: 			'../../lib/requirejs/css',
				},
				stubModules : ['text', 'hgn', 'hogan'],
				isBuild :true,
      			findNestedDependencies: true,
				inlineJSON:false,
				inlineText: false,
				optimizeCss: "standard.keepLines.keepWhitespace",
			    // configure hgn! plugin
			    hgn: {
			        templateExtension: '.mustache',
			        compilationOptions: {}
			    },
			    map: {
			        // '*' means all modules will get 'jquery-private'
			        // for their 'jquery' dependency.
			        //'*': { 'jquery': 'jquery-private' },

			        // 'jquery-private' wants the real jQuery module
			        // though. If this line was not here, there would
			        // be an unresolvable cyclic dependency.
			        //'jquery-private': { 'jquery': 'jquery' }

			        //used with https://github.com/guybedford/require-css to import spa skins
			        '*': {
			            'SPA_css': '../../lib/requirejs/css'
			        }
			    },
			    //urlArgs: { 'bust': Date.now() }, // disable on prod!.. enables cache on scripts. only needed if cache is enabled on browsers.
			    waitSeconds: 60,
			    xhtml: false
            };

Error

[15:11:54] Optimizing adminPanelTpl.js
TypeError: Path must be a string. Received [Function]
In module tree:
    adminPanelTpl
      ../../lib/requirejs/css


events.js:160
      throw er; // Unhandled 'error' event
      ^
 Error: TypeError: Path must be a string. Received [Function]
In module tree:
    adminPanelTpl
      ../../lib/requirejs/css

    at assertPath (path.js:7:11)

    at C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:26659:19
    at C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:3059:39
    at C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:2999:25
    at Function.prim.nextTick (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:26410:9)
    at Object.p.errback (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:2998:26)
    at Object.p.callback (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:2984:23)
    at Object.p.promise.then (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:3038:23)
    at build (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:26616:12)
    at runBuild (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:28624:17)
    at Object.context.execCb (C:\work\git\nas\gulp\node_modules\requirejs\bin\r.js:1946:33)
@KTamas
Copy link

KTamas commented Jun 12, 2017

I have the exact same issue

@VincenzoAsciolla
Copy link

I had the same issue using node v6.10.2 on macOS Sierra v10.12.3.
I solved downgrading the node version to 4.7.3.

@AStoker
Copy link

AStoker commented Aug 14, 2017

Wish I knew why downgrading worked...

@AStoker
Copy link

AStoker commented Aug 14, 2017

It's ultimately breaking on this line (https://github.com/guybedford/require-css/blob/master/css-builder.js#L130).

if (!siteRoot) {
      siteRoot = path.resolve(config.dir || path.dirname(config.out), config.siteRoot || '.') + '/';
      if (isWindows)
        siteRoot = siteRoot.replace(/\\/g, '/');
}

config.out is a function instead of the string that it's expecting. Despite having set the out property to be a string in the rjs config, it seems to be overwritten with this function

function (text, sourceMap) {
    output = text;
    sourceMapOutput = sourceMap;
  }

This seems to be happening inside the actual gulp-requirejs plugin here: https://github.com/jorrit/gulp-requirejs/blob/master/index.js#L56

It's possible that the behavior of path.dirname has changed such that it throws when the arguments are not a string, where previously it would have returned undefined. That would have allowed execution to continue in and older version of node...

Related: jorrit/gulp-requirejs#29

AStoker added a commit to AStoker/require-css that referenced this issue Aug 14, 2017
Resolves: guybedford#231, guybedford#229

With new Rjs, `out` can be a function (https://github.com/requirejs/r.js/blob/master/build/example.build.js#L448). Need to support dealing with `out` as being a function. In this case, simply checking if the property is a string, and if not, `toString`-ing it will allow the `siteRoot` to be determined correctly.
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

4 participants