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

bug: require(...).default is not a function #572

Closed
huixisheng opened this issue Aug 24, 2018 · 14 comments · Fixed by #574 or #815
Closed

bug: require(...).default is not a function #572

huixisheng opened this issue Aug 24, 2018 · 14 comments · Fixed by #574 or #815
Labels

Comments

@huixisheng
Copy link

Describe the bug

package.json with content

...
  "devDependencies": {
    "@webpack-cli/generate-plugin": "0.0.8",
    "@webpack-cli/init": "^0.1.0",
    "@webpack-cli/migrate": "^0.1.0",
    "webpack": "^4.17.1",
    "webpack-cli": "^3.1.0"
  },
...

What is the current behavior?

TypeError: require(...).default is not a function
    at promptForInstallation (/Users/huixisheng/x/lab/webpack/webpack-plugin-demo/node_modules/webpack-cli/bin/prompt-command.js:108:30)
    at /Users/huixisheng/x/lab/webpack/webpack-plugin-demo/node_modules/webpack-cli/bin/cli.js:45:37
    at Object.<anonymous> (/Users/huixisheng/x/lab/webpack/webpack-plugin-demo/node_modules/webpack-cli/bin/cli.js:530:3)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

To Reproduce

  1. npx webpack-cli generate-plugin
  2. vi remote default
	} else {
		require(pathForCmd)(...args); // eslint-disable-line
	}

Expected behavior

only my-webpack-plugin create.

Screenshots

image

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
  Binaries:
    Node: 8.11.1 - /usr/local/bin/node
    Yarn: 1.7.0 - /usr/local/bin/yarn
    npm: 6.2.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 68.0.3440.106
    Firefox: 54.0
    Safari: 11.1.2
  npmPackages:
    webpack: ^4.17.1 => 4.17.1 
    webpack-cli: ^3.1.0 => 3.1.0 
    webpack-defaults: ^2.3.0 => 2.3.0 
  npmGlobalPackages:
    webpack-cli: 3.1.0
    webpack: 4.17.1

Additional context
Add any other context about the problem here like linking to an similar issue you might think is the cause.

@evenstensberg
Copy link
Member

@dhruvdutt do you mind fixing this?

@dhruvdutt
Copy link
Member

This is happening because you have older version of "@webpack-cli/generate-plugin": "0.0.8" which is incompatible with the current version of webpack-cli.

Can you please upgrade to latest version 0.1.0 of @webpack-cli/generate-plugin?

@huixisheng
Copy link
Author

huixisheng commented Aug 25, 2018

@ematipico you are right. thank you.

sorry, my npm registry is https://registry.npm.taobao.org/. I do cnpm sync webpack-cli @webpack-cli/generate-plugin.

npm install @webpack-cli/generate-plugin@0.1.0`, it works, but with error

➜  webpack-plugin-demo git:(master) ✗ npx webpack-cli generate-plugin
? Plugin name my-1

        Your project must be inside a folder named my-1
        I will create this folder for you.
        
Failed to create directory null
events.js:183
      throw er; // Unhandled 'error' event
      ^

AssertionError [ERR_ASSERTION]: Trying to copy from a source that does not exist: /Users/huixisheng/x/lab/webpack/webpack-plugin-demo/node_modules/@webpack-cli/generate-plugin/test/test-utils.js.tpl

I copy the miss files in the repository https://github.com/webpack/webpack-cli/tree/master/packages/generate-plugin. It can work. but will do scripts webpack-defaults, it's default config ?

npm WARN deprecated @types/commander@2.12.2: This is a stub types definition for commander (https://github.com/tj/commander.js). commander provides its own type definitions, so you don't need @types/commander installed!

> webpack-defaults@2.3.0 postinstall /Users/huixisheng/x/lab/webpack/webpack-plugin-demo/node_modules/webpack-defaults
> node lib/post_install.js

Update /Users/huixisheng/x/lab/webpack/webpack-plugin-demo/package.json
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN webpack-plugin-demo@1.0.0 No repository field.

+ bluebird@3.5.1
+ webpack-defaults@2.3.0
added 1 package from 1 contributor, removed 4 packages and updated 1 package in 13.647s

> webpack-plugin-demo@1.0.0 defaults /Users/huixisheng/x/lab/webpack/webpack-plugin-demo
> webpack-defaults

Synchronizing config files...
Create .babelrc
Create codecov.yml
Create .eslintignore
Create .gitignore
Create .gitattributes
Create .github/ISSUE_TEMPLATE.md

I try to install @webpack-cli/generate-plugin@0.1.0. but Can't find package @webpack-cli/generate-plugin@^0.1.0.

image

image

I will do with npm cache verify, yarn cache clean in the process.

@ematipico
Copy link
Contributor

ematipico commented Aug 25, 2018

https://www.npmjs.com/package/@webpack-cli/generate-plugin

It looks like it's there. Are you hitting the correct registry?

@evenstensberg
Copy link
Member

Seems like we might need to support China ( Tabao ) as well. Makes sense?

@ematipico
Copy link
Contributor

Yes

dhruvdutt added a commit to dhruvdutt/webpack-cli that referenced this issue Aug 25, 2018
dhruvdutt added a commit to dhruvdutt/webpack-cli that referenced this issue Aug 25, 2018
@dhruvdutt
Copy link
Member

@huixisheng We're identified and resolved the issue. We'll soon release a new version with the fix.

@huixisheng
Copy link
Author

👍

but will do scripts webpack-defaults, it's default config ?

npm WARN deprecated @types/commander@2.12.2: This is a stub types definition for commander (https://github.com/tj/commander.js). commander provides its own type definitions, so you don't need @types/commander installed!

> webpack-defaults@2.3.0 postinstall /Users/huixisheng/x/lab/webpack/webpack-plugin-demo/node_modules/webpack-defaults
> node lib/post_install.js

@evenstensberg
Copy link
Member

Could you elaborate @huixisheng ?

@huixisheng
Copy link
Author

The generated files are all redundant except my-webpack-plugin folder ?

image

@evenstensberg
Copy link
Member

I don't think I understand your question. Are you trying to run webpack-defaults and you are wondering if it is ok to run it through webpack-cli?

@duzy
Copy link

duzy commented Sep 15, 2018

I came across the same issue, this is properly a fix:

	} else {
          let p = require(pathForCmd), c = p[packages];
          if (typeof c !== 'function' && typeof p.default === 'function') {
	    c = p.default;
          }
          c(...args); // eslint-disable-line
	}

which replaced the original (prompt-command.js):

	} else {
          require(pathForCmd).default(...args); // eslint-disable-line
	}

the strange things in this fix is about packages -- if it's not indicating the sub-command.

@evenstensberg
Copy link
Member

Maybe you can do a PR to fix this? That would be great 🤗😍

duzy added a commit to collects/webpack-cli that referenced this issue Sep 15, 2018
the strange things in this fix is about packages -- if it's not indicating the sub-command or a list of commands?
@duzy
Copy link

duzy commented Sep 15, 2018

Maybe you can do a PR to fix this? That would be great

master...duzy:patch-1

#589

@ematipico ematipico reopened this Sep 15, 2018
@evenstensberg evenstensberg changed the title require(...).default is not a function bug: require(...).default is not a function Feb 5, 2019
sendilkumarn pushed a commit that referenced this issue Apr 2, 2019
* fix(prompt-command, serve): force default package export, add serve default

ISSUES CLOSED: #572

* misc(serve): remove unnecessary exports, update docs
misterdev pushed a commit to misterdev/webpack-cli that referenced this issue Apr 23, 2019
…pack#815)

* fix(prompt-command, serve): force default package export, add serve default

ISSUES CLOSED: webpack#572

* misc(serve): remove unnecessary exports, update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants