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

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

Closed
mattferrin opened this issue Feb 8, 2017 · 20 comments
Closed

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

mattferrin opened this issue Feb 8, 2017 · 20 comments
Labels

Comments

@mattferrin
Copy link

@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
Copy link
Author

@mattferrin 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
Copy link
Contributor

@wincent 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 parent folder, npm install succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) 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 npm install succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) npm run build succeeds on Mac, fails on Windows (Windows_NT 6.3.9600) Feb 8, 2017
@mattferrin
Copy link
Author

@mattferrin 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
Copy link
Contributor

@wincent 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
Copy link
Author

@mattferrin mattferrin commented Feb 8, 2017

cd example
npm install
npm start
@mattferrin
Copy link
Author

@mattferrin 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
Copy link
Contributor

@wincent 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
Copy link
Author

@mattferrin 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
Copy link
Contributor

@wincent wincent commented Feb 8, 2017

Please send one if you figure it out.

@mattferrin
Copy link
Author

@mattferrin 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
Copy link
Contributor

@wincent 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
Copy link
Author

@mattferrin 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
Copy link
Contributor

@wincent 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
Copy link
Author

@mattferrin 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
Copy link

@anilchoudhary9 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
Copy link

@jaydenseric 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.

@coolapollo
Copy link

@coolapollo coolapollo commented Sep 4, 2019

PS C:\Users\Xxx\Desktop\9-forkify> npm run dev

forkify@1.0.0 dev C:\Users\Apollo\Desktop\9-forkify
webpack --mode development

webpack 2.7.0
Usage: https://webpack.js.org/api/cli/
Usage without config file: webpack []
Usage with config file: webpack

Config options:
--config Path to the config file
[string] [default: webpack.config.js or webpackfile.js]
--env Environment passed to the config, when it is a function

Basic options:
--context The root directory for resolving entry point and stats
[string] [default: The current directory]
--entry The entry point [string]
--watch, -w Watch the filesystem for changes [boolean]
--debug Switch loaders to debug mode [boolean]
--devtool Enable devtool for better debugging experience (Example:
--devtool eval-cheap-module-source-map) [string]
-d shortcut for --debug --devtool eval-cheap-module-source-map
--output-pathinfo [boolean]
-p shortcut for --optimize-minimize --define
process.env.NODE_ENV="production" [boolean]
--progress Print compilation progress in percentage [boolean]

Module options:
--module-bind Bind an extension to a loader [string]
--module-bind-post [string]
--module-bind-pre [string]

Output options:
--output-path The output path for compilation assets
[string] [default: The current directory]
--output-filename The output filename of the bundle
[string] [default: [name].js]
--output-chunk-filename The output filename for additional chunks
[string] [default: filename with [id] instead of [name] or [id] prefixed]
--output-source-map-filename The output filename for the SourceMap [string]
--output-public-path The public path for the assets [string]
--output-jsonp-function The name of the jsonp function used for chunk
loading [string]
--output-pathinfo Include a comment with the request for every
dependency (require, import, etc.) [boolean]
--output-library Expose the exports of the entry point as library
[string]
--output-library-target The type for exposing the exports of the entry
point as library [string]

Advanced options:
--records-input-path Path to the records file (reading) [string]
--records-output-path Path to the records file (writing) [string]
--records-path Path to the records file [string]
--define Define any free var in the bundle [string]
--target The targeted execution environment [string]
--cache Enable in memory caching
[boolean] [default: It's enabled by default when watching]
--watch-stdin, --stdin Exit the process when stdin is closed [boolean]
--watch-aggregate-timeout Timeout for gathering changes while watching
--watch-poll The polling interval for watching (also enable
polling) [boolean]
--hot Enables Hot Module Replacement [boolean]
--prefetch Prefetch this request (Example: --prefetch
./file.js) [string]
--provide Provide these modules as free vars in all modules
(Example: --provide jQuery=jquery) [string]
--labeled-modules Enables labeled modules [boolean]
--plugin Load this plugin [string]
--bail Abort the compilation on first error [boolean]
--profile Profile the compilation and include information in
stats [boolean]

Resolving options:
--resolve-alias Setup a module alias for resolving (Example:
jquery-plugin=jquery.plugin) [string]
--resolve-extensions Setup extensions that should be used to resolve
modules (Example: --resolve-extensions .es6 .js)
[array]
--resolve-loader-alias Setup a loader alias for resolving [string]

Optimizing options:
--optimize-max-chunks Try to keep the chunk count below a limit
--optimize-min-chunk-size Try to keep the chunk size above a limit
--optimize-minimize Minimize javascript and switches loaders to
minimizing [boolean]

Stats options:
--color, --colors Enables/Disables colors on the console
[boolean] [default: (supports-color)]
--sort-modules-by Sorts the modules list by property in module
[string]
--sort-chunks-by Sorts the chunks list by property in chunk[string]
--sort-assets-by Sorts the assets list by property in asset[string]
--hide-modules Hides info about modules [boolean]
--display-exclude Exclude modules in the output [string]
--display-modules Display even excluded modules in the output
[boolean]
--display-max-modules Sets the maximum number of visible modules in
output [number]
--display-chunks Display chunks in the output [boolean]
--display-entrypoints Display entry points in the output [boolean]
--display-origins Display origins of chunks in the output [boolean]
--display-cached Display also cached modules in the output[boolean]
--display-cached-assets Display also cached assets in the output [boolean]
--display-reasons Display reasons about module inclusion in the
output [boolean]
--display-depth Display distance from entry point for each module
[boolean]
--display-used-exports Display information about used exports in modules
(Tree Shaking) [boolean]
--display-provided-exports Display information about exports provided from
modules [boolean]
--display-error-details Display details about errors [boolean]
--verbose Show more details [boolean]

Options:
--help, -h Show help [boolean]
--version, -v Show version number [boolean]
--json, -j Prints the result as JSON. [boolean]

Unknown argument: mode
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! forkify@1.0.0 dev: webpack --mode development
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the forkify@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Xxx\AppData\Roaming\npm-cache_logs\2019-09-04T03_38_26_243Z-debug.log
PS C:\Users\Xxx\Desktop\9-forkify>

Need help, running mine on windows 10 not sure why it’s not working.

@coolapollo
Copy link

@coolapollo coolapollo commented Sep 4, 2019

{
“name": "forkify",
"version": "1.0.0",
"description": "forkify project",
"main": "index.js",
"scripts": {
"dev": "webpack --mode development",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development --open"
},
"author": "Xxx",
"license": "ISC",
"devDependencies": {
"webpack": "^2.7.0",
"webpack-cli": "^3.3.7",
"webpack-dev-server": "^3.8.0"
}
}

That’s my package.json file

@acao
Copy link
Member

@acao acao commented Sep 4, 2019

@coolapollo it looks like you're having an unrelated issue with webpack, not running a version that supports the mode arg. Please check out the webpack support community for some answers.

@acao
Copy link
Member

@acao acao commented Sep 4, 2019

So the only yarn script commands left that dont support windows are version/publiahing related now, and none of the maintainers use windows yet, but we will eventually convert all the tooling. lots of it is being rewritten entirely, so i try to rewrite everything as node scripts, use rimraf and cross env, etc. if anyone is trying to contribute and there are os specific isaues with any of the build process, please reopen this!

@acao acao closed this Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.