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

npm run build succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) #318

Open
mattferrin opened this Issue Feb 8, 2017 · 16 comments

Comments

Projects
None yet
4 participants
@mattferrin

mattferrin commented Feb 8, 2017

C:\Dev\graphiql>npm install && npm run build

> graphiql@0.9.2 prepublish C:\Dev\graphiql
> . ./resources/prepublish.sh

'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! node v6.9.5
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! graphiql@0.9.2 prepublish: `. ./resources/prepublish.sh`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the graphiql@0.9.2 prepublish script '. ./resources/prepublish.sh'.
@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 8, 2017

I've changed the .sh files to Node .js files, but get the following error:

Uncaught ReferenceError: GraphiQL is not defined
    at (index):136
(anonymous) @ (index):136
      ReactDOM.render(
        React.createElement(GraphiQL, {
          fetcher: graphQLFetcher,
          query: parameters.query,
          variables: parameters.variables,
          operationName: parameters.operationName,
          onEditQuery: onEditQuery,
          onEditVariables: onEditVariables,
          onEditOperationName: onEditOperationName
        }),
        document.getElementById('graphiql')
      );

mattferrin commented Feb 8, 2017

I've changed the .sh files to Node .js files, but get the following error:

Uncaught ReferenceError: GraphiQL is not defined
    at (index):136
(anonymous) @ (index):136
      ReactDOM.render(
        React.createElement(GraphiQL, {
          fetcher: graphQLFetcher,
          query: parameters.query,
          variables: parameters.variables,
          operationName: parameters.operationName,
          onEditQuery: onEditQuery,
          onEditVariables: onEditVariables,
          onEditOperationName: onEditOperationName
        }),
        document.getElementById('graphiql')
      );
@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Feb 8, 2017

Contributor

Thanks for bringing this up @mattferrin. We'd love to get the build working on Windows machines, but I personally don't have a machine to do any testing on. If you can identify the changes necessary to get it working there, we can fix this together.

I've changed the .sh files to Node .js files, but get the following error:

Can you share the changes you made, and also what you did to get the error?

Contributor

wincent commented Feb 8, 2017

Thanks for bringing this up @mattferrin. We'd love to get the build working on Windows machines, but I personally don't have a machine to do any testing on. If you can identify the changes necessary to get it working there, we can fix this together.

I've changed the .sh files to Node .js files, but get the following error:

Can you share the changes you made, and also what you did to get the error?

@wincent wincent changed the title from parent folder, npm install succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) to npm install succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) Feb 8, 2017

@wincent wincent added the windows label Feb 8, 2017

@mattferrin mattferrin changed the title from npm install succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) to npm run build succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) Feb 8, 2017

@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 8, 2017

The root issue is really that running any .sh file from the command prompt fails. runing Node .js scripts seems the right solution.

package.json

  "scripts": {
    "build": "node ./resources/build.js",
    "check": "flow check",
    "dev": "babel-node test/server.js",
    "lint": "eslint src",
    "prepublish": "node ./resources/prepublish.js",
    "preversion": ". ./resources/checkgit.sh && npm test",
    "test": "npm run lint && npm run check && npm run testonly",
    "testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha"
  },

./resources/build.sh

var exec = require('child_process').exec;

var stdout = function (command) {
  exec(command, function(error, stdout, stderr) {
    console.log(stdout);
  });
};

stdout("echo \"Running node ./resources/build.js\"");

stdout("set -e");

stdout("if [ ! -d \"node_modules/.bin\" ]; then");
  stdout("echo \"Be sure to run \`npm install\` before building GraphiQL.");
  stdout("exit 1");
stdout("fi");

stdout("rm -rf dist/ && mkdir -p dist/");
stdout("babel src --ignore __tests__ --out-dir dist/");
stdout("echo \"Bundling graphiql.js...\"");
stdout("browserify -g browserify-shim -s GraphiQL dist/index.js > graphiql.js");
stdout("echo \"Bundling graphiql.min.js...\"");
stdout("browserify -g browserify-shim -g uglifyify -s GraphiQL dist/index.js 2> /dev/null | uglifyjs -c --screw-ie8 > graphiql.min.js 2> /dev/null");
stdout("echo \"Bundling graphiql.css...\"");
stdout("postcss --use autoprefixer css/*.css -d dist/");
stdout("cat dist/*.css > graphiql.css");
stdout("echo \"Done\"");

./resources/prepublish.sh

var exec = require('child_process').exec;

var stdout = function (command) {
  exec(command, function(error, stdout, stderr) {
    console.log(stdout);
  });
};

stdout("echo \"Running node ./resources/prepublish.js\"");

// # Because of a long-running npm issue (https://github.com/npm/npm/issues/3059)
// # prepublish runs after `npm install` and `npm pack`.
// # In order to only run prepublish before `npm publish`, we have to check argv.
stdout("if node -e \"process.exit(($npm_config_argv).original[0].indexOf('pu') === 0)\"; then; exit 0; fi");

// # Publishing to NPM is currently supported by Travis CI, which ensures that all
// # tests pass first and the deployed module contains the correct file structure.
// # In order to prevent inadvertently circumventing this, we ensure that a CI
// # environment exists before continuing.
stdout("if [ \"$CI\" != true ]; then;")
  stdout("echo \"\n\n\n  \033[101;30m Only Travis CI can publish to NPM. \033[0m\" 1>&2;");
  stdout("echo \"  Ensure git is left is a good state by backing out any commits and deleting any tags.\" 1>&2;");
  stdout("echo \"  Then read CONTRIBUTING.md to learn how to publish to NPM.\n\n\n\" 1>&2;");
  stdout("exit 1;");
stdout("fi;");

stdout("npm run build;");

But right now, after this, the root React element is null and I don't know why.

mattferrin commented Feb 8, 2017

The root issue is really that running any .sh file from the command prompt fails. runing Node .js scripts seems the right solution.

package.json

  "scripts": {
    "build": "node ./resources/build.js",
    "check": "flow check",
    "dev": "babel-node test/server.js",
    "lint": "eslint src",
    "prepublish": "node ./resources/prepublish.js",
    "preversion": ". ./resources/checkgit.sh && npm test",
    "test": "npm run lint && npm run check && npm run testonly",
    "testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha"
  },

./resources/build.sh

var exec = require('child_process').exec;

var stdout = function (command) {
  exec(command, function(error, stdout, stderr) {
    console.log(stdout);
  });
};

stdout("echo \"Running node ./resources/build.js\"");

stdout("set -e");

stdout("if [ ! -d \"node_modules/.bin\" ]; then");
  stdout("echo \"Be sure to run \`npm install\` before building GraphiQL.");
  stdout("exit 1");
stdout("fi");

stdout("rm -rf dist/ && mkdir -p dist/");
stdout("babel src --ignore __tests__ --out-dir dist/");
stdout("echo \"Bundling graphiql.js...\"");
stdout("browserify -g browserify-shim -s GraphiQL dist/index.js > graphiql.js");
stdout("echo \"Bundling graphiql.min.js...\"");
stdout("browserify -g browserify-shim -g uglifyify -s GraphiQL dist/index.js 2> /dev/null | uglifyjs -c --screw-ie8 > graphiql.min.js 2> /dev/null");
stdout("echo \"Bundling graphiql.css...\"");
stdout("postcss --use autoprefixer css/*.css -d dist/");
stdout("cat dist/*.css > graphiql.css");
stdout("echo \"Done\"");

./resources/prepublish.sh

var exec = require('child_process').exec;

var stdout = function (command) {
  exec(command, function(error, stdout, stderr) {
    console.log(stdout);
  });
};

stdout("echo \"Running node ./resources/prepublish.js\"");

// # Because of a long-running npm issue (https://github.com/npm/npm/issues/3059)
// # prepublish runs after `npm install` and `npm pack`.
// # In order to only run prepublish before `npm publish`, we have to check argv.
stdout("if node -e \"process.exit(($npm_config_argv).original[0].indexOf('pu') === 0)\"; then; exit 0; fi");

// # Publishing to NPM is currently supported by Travis CI, which ensures that all
// # tests pass first and the deployed module contains the correct file structure.
// # In order to prevent inadvertently circumventing this, we ensure that a CI
// # environment exists before continuing.
stdout("if [ \"$CI\" != true ]; then;")
  stdout("echo \"\n\n\n  \033[101;30m Only Travis CI can publish to NPM. \033[0m\" 1>&2;");
  stdout("echo \"  Ensure git is left is a good state by backing out any commits and deleting any tags.\" 1>&2;");
  stdout("echo \"  Then read CONTRIBUTING.md to learn how to publish to NPM.\n\n\n\" 1>&2;");
  stdout("exit 1;");
stdout("fi;");

stdout("npm run build;");

But right now, after this, the root React element is null and I don't know why.

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Feb 8, 2017

Contributor

But right now, after this, the root React element is null and I don't know why.

How are you running GraphiQL? (npm run dev?)

Contributor

wincent commented Feb 8, 2017

But right now, after this, the root React element is null and I don't know why.

How are you running GraphiQL? (npm run dev?)

@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 8, 2017

cd example
npm install
npm start

mattferrin commented Feb 8, 2017

cd example
npm install
npm start
@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 8, 2017

Actually, npm run dev seems to work, but I know the scripts would not run without the changes to Node instead of shell.

mattferrin commented Feb 8, 2017

Actually, npm run dev seems to work, but I know the scripts would not run without the changes to Node instead of shell.

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Feb 8, 2017

Contributor

I know the scripts would not run without the changes to Node instead of shell.

Yep, that makes perfect sense (except for people running in some sort of POSIX compatibility environment). I think changing the shell scripts to node scripts makes sense, even if they are not quite as "nice" to write.

Contributor

wincent commented Feb 8, 2017

I know the scripts would not run without the changes to Node instead of shell.

Yep, that makes perfect sense (except for people running in some sort of POSIX compatibility environment). I think changing the shell scripts to node scripts makes sense, even if they are not quite as "nice" to write.

@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 8, 2017

I find it troubling that

cd example
npm install
npm start

doesn't work for me yet.

Otherwise I'd be close to a pull request on this.

mattferrin commented Feb 8, 2017

I find it troubling that

cd example
npm install
npm start

doesn't work for me yet.

Otherwise I'd be close to a pull request on this.

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Feb 8, 2017

Contributor

Please send one if you figure it out.

Contributor

wincent commented Feb 8, 2017

Please send one if you figure it out.

@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 8, 2017

The command cat dist/*.css > graphiql.css works from Git Bash, but not from Node exec. Cool... Don't know alternative yet.

mattferrin commented Feb 8, 2017

The command cat dist/*.css > graphiql.css works from Git Bash, but not from Node exec. Cool... Don't know alternative yet.

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Feb 8, 2017

Contributor

Well, it is literally just concatenating the files, so could get the listing with fs.readdirSync, read the files with fs.readFileSync, concat in JS, then fs.writeFileSync the result.

Contributor

wincent commented Feb 8, 2017

Well, it is literally just concatenating the files, so could get the listing with fs.readdirSync, read the files with fs.readFileSync, concat in JS, then fs.writeFileSync the result.

@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 9, 2017

I'm making progress by testing process.platform on everything that errors. I just use type instead of cat, but need to address a lot more errors since I'm logging them to the console now and can actually see them :) Making progress on this.

mattferrin commented Feb 9, 2017

I'm making progress by testing process.platform on everything that errors. I just use type instead of cat, but need to address a lot more errors since I'm logging them to the console now and can actually see them :) Making progress on this.

@wincent

This comment has been minimized.

Show comment
Hide comment
@wincent

wincent Feb 9, 2017

Contributor

What do you think of my suggestion to use fs.* methods instead, which are platform-agnostic, rather than engaging in "UserAgent"-sniffing with process.platform. If we do this right, once, we'll never have to do it again.

Contributor

wincent commented Feb 9, 2017

What do you think of my suggestion to use fs.* methods instead, which are platform-agnostic, rather than engaging in "UserAgent"-sniffing with process.platform. If we do this right, once, we'll never have to do it again.

@mattferrin

This comment has been minimized.

Show comment
Hide comment
@mattferrin

mattferrin Feb 9, 2017

I agree with you in principle, but I'd like to be that small step in the right direction.

My most likely final issue with the build script is this:

"Bundling graphiql.min.js..."
The process cannot access the file because it is being used by another process.
child_process.js:526
    throw err;
    ^

Error: Command failed: browserify -g browserify-shim -g uglifyify -s GraphiQL di
st/index.js 2> /dev/null | uglifyjs -c --screw-ie8 > graphiql.min.js 2> /dev/nul
l
    at checkExecSyncError (child_process.js:483:13)
    at execSync (child_process.js:523:13)
    at stdout (C:\Dev\graphiql\resources\build.js:7:3)
    at Object.<anonymous> (C:\Dev\graphiql\resources\build.js:29:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)

I haven't thought it through yet though.

mattferrin commented Feb 9, 2017

I agree with you in principle, but I'd like to be that small step in the right direction.

My most likely final issue with the build script is this:

"Bundling graphiql.min.js..."
The process cannot access the file because it is being used by another process.
child_process.js:526
    throw err;
    ^

Error: Command failed: browserify -g browserify-shim -g uglifyify -s GraphiQL di
st/index.js 2> /dev/null | uglifyjs -c --screw-ie8 > graphiql.min.js 2> /dev/nul
l
    at checkExecSyncError (child_process.js:483:13)
    at execSync (child_process.js:523:13)
    at stdout (C:\Dev\graphiql\resources\build.js:7:3)
    at Object.<anonymous> (C:\Dev\graphiql\resources\build.js:29:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)

I haven't thought it through yet though.

@anilchoudhary9

This comment has been minimized.

Show comment
Hide comment
@anilchoudhary9

anilchoudhary9 Sep 29, 2017

i m getting error of following type at this postion.
I include this following code at the my opening js file.
require('getmac').getMac(function(macAddress,err){
if (err) throw err
console.log(macAddress)
console.log('mac run')
})
Cannot read property 'indexOf' of undefined
isWindows = process.platform.indexOf('win') === 0;

I want to get macAddress of the running system

anilchoudhary9 commented Sep 29, 2017

i m getting error of following type at this postion.
I include this following code at the my opening js file.
require('getmac').getMac(function(macAddress,err){
if (err) throw err
console.log(macAddress)
console.log('mac run')
})
Cannot read property 'indexOf' of undefined
isWindows = process.platform.indexOf('win') === 0;

I want to get macAddress of the running system

@jaydenseric

This comment has been minimized.

Show comment
Hide comment
@jaydenseric

jaydenseric Sep 26, 2018

Windows users, have you considered using Windows Subsystem for Linux?

The Windows Subsystem for Linux lets developers run GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.

It's a Windows 10 feature.

jaydenseric commented Sep 26, 2018

Windows users, have you considered using Windows Subsystem for Linux?

The Windows Subsystem for Linux lets developers run GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.

It's a Windows 10 feature.

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