webpack-contrib / webpack-defaults

Defaults to be shared across webpack projects
MIT License
108 stars 28 forks source link

No script command created on Windows 10 #181

Open Legends opened 4 years ago

Legends commented 4 years ago

Expected Behavior

A created script command in package.json

Actual Behavior

nothing is created

Code

// webpack.config.js
// If your code blocks are over 20 lines, please paste a link to a gist
// (https://gist.github.com).
// additional code, HEY YO remove this block if you don't need it

package.json

{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10",
    "@webpack-contrib/defaults": "^6.3.0"
  },
  "dependencies": {
    "lodash": "^4.17.15",
    "tmp": "^0.1.0"
  }
}

How Do We Reproduce?

Legends commented 4 years ago

In order to make it work on windows 10:

create and execute the following index.js file:

const run = require("@webpack-contrib/defaults/dist");
run();

or add the command by hand to scripts after installation:

scripts:{
 "default" : "webpack-defaults"
}
Legends commented 4 years ago

Errors experienced on windows during command execution:

1.)

del-cli dist

'del-cli' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1

2.)

babel: src does not exist npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! loader-example@1.0.0 build: cross-env NODE_ENV=production babel src -d dist --copy-files npm ERR! Exit status 2

alexander-akait commented 4 years ago

Strange, can you provide more information or steps? Do you have src/dist directories?

Legends commented 4 years ago

No, I don't have src/dist directories, but nevertheless it shouldn't throw an error.

I've setup a blank project with no dependencies:

  1. yarn init -y
  2. yarn add --dev @webpack-contrib/defaults --> @webpack-contrib/defaults": "^6.3.0

No errors are thrown, but the script command is NOT created. In this case, no errors thrown is actually not good ;-)

3.) I add the script section by hand:

 "scripts":{
    "default" : "webpack-defaults"
   }
  1. Yarn default

Now I get the errors mentioned above:

errors: 1:)

'del-cli' is not recognized as an internal or external command, operable program or batch file. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! nf@1.0.0 clean: del-cli dist npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the nf@1.0.0 clean script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

2.)

babel: src does not exist npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! nf@1.0.0 build: cross-env NODE_ENV=production babel src -d dist --copy-files npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the nf@1.0.0 build script.

3.)

Done. Happy webpacking!

Create test/loader.test.js (node:17420) UnhandledPromiseRejectionWarning: MrmError: copyFiles: source file not found: D:\xxx\Newfolder\node_modules\@webpack-contrib\defaults\templates\test\options.test.js at D:\xxx\Newfolder\node_modules\mrm-core\src\fs.js:32:10 at Array.forEach () at copyFiles (D:\xxx\Newfolder\node_modules\mrm-core\src\fs.js:29:21) at D:\xxx\Newfolder\node_modules\@webpack-contrib\defaults\dist\tasks\templates.js:26:7 (node:17420) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:17420) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. Done in 51.05s.

Legends commented 4 years ago

@evilebottnawi What triggers the post_install.js in order to run? Apparently id does not get triggered in my case.

alexander-akait commented 4 years ago

What is use case for using webpack-defaults?

Legends commented 4 years ago

Use-case? You would use if you want to write a loader/plugin as it sets up many things upfront.

alexander-akait commented 4 years ago

I don't have windows nearby, maybe we have some bugs with windows, I will try to look at that in next weekend (+ setup windows machine)

Legends commented 4 years ago

That's why I asked you, what triggers this postinstall.js so i could take a look on my machine.

alexander-akait commented 4 years ago

https://github.com/webpack-contrib/webpack-defaults/blob/master/lib/post_install.js

Legends commented 4 years ago

Yes, this is the mentioned file, but how does it get triggered/run, is there an install hook? Cause I can't see any on my side.

ash-r1 commented 4 years ago

I met same issue on macOS 10.15.3, under ~/Documents/my-experiment-ish directory has right permission.

floralWallpaper commented 4 years ago

There was actually no script written for me on a mac either.

I did as Legends did and added the script myself. I got the UnhandledPromiseRejectionWarning error.

steinybot commented 3 years ago

What worked for me macOS Big Sur 11.1 was to run:

npm init
npm install @webpack-contrib/defaults --save-dev
node_modules/@webpack-contrib/defaults/lib/post_install.js
npm run defaults

Thanks to @Legends for the hint in the PR.

peterhpchen commented 3 years ago

I have the same issue in macOS Big Sur 11.4. I have to add the command defaults by myself.