Process.platform.match is not a function

This just started happening. I cannot find (or think of) any reason for it. Any thoughts?

Hello my fine crickets. Was this question too dumb to deserve an answer?

I really don’t know.

Wish I had a clue what I did to deserve this message.

Did you manage to get this working?

I don’t have an answer for you but there are quite a number of moving bits and idiosyncrasies to deal with that it’ll take some time to understand where the one thing stops and the next thing starts i.r.o. node / browser / library

In any event the process.platform appears to be related to node: https://nodejs.org/api/process.html#process_process_platform

The match is a JavaScript method on a string: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/match

What environment is this code running in and do you have, by any chance, some process.platform structure in your own code? It seem to me… and this is a wild guess… that the match thingy may not be a function :thinking:

It is just a matter of finding out why though :slight_smile:

It is so easy to overwrite/replace anything in JavaScript that any error may be a red herring.

The errors in donejs are often daunting. The stack is so deep that it’s often trial and error to figure out where a problem occurs.

In this case, I am running nothing other than donejs. I started with their ‘in-depth’ guide and built on that. I added a css framework but doubt that has impact and, so far, have only done navigation stuff, ie, update the data model to select different templates that mostly just say, “the blah component”.

That is to say, I don’t think I have done anything to the process.platform. Especially, as I dug in to find, I have not deleted it. Match() is not a function because process.platform does not exist.

The weird thing is that this wasn’t always happening. Because the dev environment has so many console items, I’m not sure when it appeared so I can’t track it back to any specific change I made.

Of course, it doesn’t seem to matter either. It’s disturbing though.

Thanks for answering.

Any chance of sharing your code somewhere?

So, there are a whole bunch of files and I couldn’t think about how to present them to you. Eventually, inspiration struck and I just told my demo server to act as if it were a dev server. All of the files are loaded separately. (It also does a fine display of the problem we’ve discussed with ampersands.) The error shows quite nicely in the browser console.

Thanks for taking a look.

http://demo.careplanner.tqtmp.org/

Ah,

The culprit appears to be something called npm-load that is used by steal. It does this:

var translateConfig = function(loader, packages, options){
	var g = loader.global;
	if(!g.process) {
		g.process = {
			cwd: function(){
				var baseURL = loader.baseURL;
				return baseURL;
			},
			browser: true,
			env: {
				NODE_ENV: loader.env
			}
		};
	}

That bit seems related to fiddling with the package.json file and creates a process object on the window object. This runs after the following steal magic:

(function() {
  var isWorker = typeof self !== 'undefined' && typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
  var isBrowser = typeof window != 'undefined' && !isWorker;
  var isWindows = typeof process != 'undefined' && !!process.platform.match(/^win/);
  var Promise = __global.Promise || require('when/es6-shim/Promise');

However, you appear to have some live-reload happening… or something that is triggering the whole business to execute again. On the second run, since the environment is still in the same state, that process object is still floating about. And guess what… it does not have a platform object and we are greeted with the failure. I would suggest you log an issue with stealjs as this is quite easily fixed. Perhaps Matthew has seen this thread and has been keeping a keen eye on it and is about to pounce!

You are a genius. I have no idea how to debug such a thing. Thanks. If Matthew doesn’t show up in the next day, I will log an issue.

made a pull request on steal/system-npm

1 Like