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

TypeError: merge.all is not a function #17

Closed
nonoroazoro opened this issue Nov 29, 2018 · 14 comments · Fixed by #21
Closed

TypeError: merge.all is not a function #17

nonoroazoro opened this issue Nov 29, 2018 · 14 comments · Fixed by #21

Comments

@nonoroazoro
Copy link

I'm using webpack 4.26.1 with rest.js, but after a successful bundling the application encountered this error TypeError: merge.all is not a function.

Then I tried the TypeScript compiler, while it works perfect.

I've found the simillar issue(#1129 ), but it doesn't help at all.

Here is the error stack:

TypeError: merge.all is not a function
	at defaultOptions (webpack:///./node_modules/@octokit/endpoint/lib/merge.js?:19:19)
	at withDefaults (webpack:///./node_modules/@octokit/endpoint/with-defaults.js?:8:20)
	at eval (webpack:///./node_modules/@octokit/endpoint/index.js?:4:18)
	at Object../node_modules/@octokit/endpoint/index.js (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:96:1)
	at __webpack_require__ (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:20:30)
	at eval (webpack:///./node_modules/@octokit/request/index.js?:1:18)
	at Object../node_modules/@octokit/request/index.js (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:217:1)
	at __webpack_require__ (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:20:30)
	at eval (webpack:///./node_modules/@octokit/rest/lib/constructor.js?:3:18)
	at Object../node_modules/@octokit/rest/lib/constructor.js (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:306:1)
	at __webpack_require__ (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:20:30)
	at eval (webpack:///./node_modules/@octokit/rest/lib/factory.js?:3:17)
	at Object../node_modules/@octokit/rest/lib/factory.js (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:328:1)
	at __webpack_require__ (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:20:30)
	at eval (webpack:///./node_modules/@octokit/rest/lib/core.js?:1:17)
	at Object../node_modules/@octokit/rest/lib/core.js (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:317:1)
	at __webpack_require__ (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:20:30)
	at eval (webpack:///./node_modules/@octokit/rest/index.js?:1:17)
	at Object../node_modules/@octokit/rest/index.js (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:295:1)
	at __webpack_require__ (/Users/Zoro/Workspace/vscode-syncing/dist/extension.js:20:30)

After debugging into the package deepmerge, I got this:

default

Note that the webpack imports the deepmerge from "./node_modules/deepmerge/dist/es.js", which is an ES module. But it doesn't extract the merge object from the default property of the imported ES module.
Thus, calling merge.all will raise the error, instead it should be called as merge.default.all, but of cause it cannot be an acceptable solution.

@nonoroazoro nonoroazoro changed the title Webpack Build Error: Failed to TypeError: merge.all is not a function Nov 29, 2018
@nonoroazoro nonoroazoro reopened this Nov 29, 2018
@gr2m
Copy link
Contributor

gr2m commented Nov 29, 2018

Can you check if https://github.com/octokit/rest.js/issues/1129 helps?

@nonoroazoro
Copy link
Author

@gr2m Actually I've found the solution, just add the followings into the webpack configuration file:

resolve: {
    alias: {
        deepmerge$: 'deepmerge/dist/umd.js',
    }
}

It seems that it's an issue introduced by deepmerge, not rest.js

Thanks anyway!

nonoroazoro referenced this issue in nonoroazoro/vscode-syncing Nov 29, 2018
@nonoroazoro
Copy link
Author

I'd close this issue since it has been solved :)

@gr2m
Copy link
Contributor

gr2m commented Nov 29, 2018

Is there something I can do in @octokit/rest so others won’t run into it?

@nonoroazoro
Copy link
Author

nonoroazoro commented Nov 30, 2018

@gr2m I think I've found the root cause after debugging, here's the explanation:

  1. In the file merge.js of the project endpoint.js, we import the deepmerge by the function require(), which means we expect to import the deepmerge as a Commonjs Module.

  2. But, webpack will try to import the deepmerge's ES Module version by default, since the module field of deepmerge's package.json is set to "dist/es.js".

  3. Thus, we actually import an ES Module (deepmerge) in a Commonjs Module file (merge.js) via require(), which leads to the error.

So the viable solution is either to require the Commonjs Module, or import the ES Module.

I think you can simply add a webpack config file into the project endpoint.js, and add the alias to force the webpack to import the Commonjs Module version of deepmerge (like what I did in my project).

resolve: {
    alias: {
        deepmerge$: 'deepmerge/dist/umd.js',
    }
}

And don't forget to update the scripts in the package.json file.

@brunolemos
Copy link

brunolemos commented Dec 1, 2018

Just got this after upgrading and making all the required changes.

Changing the webpack is not a viable solution since I use create-react-app.

Please make the fix on @octokit side instead :)
This should be reopened.

image

@nonoroazoro nonoroazoro reopened this Dec 1, 2018
@gr2m
Copy link
Contributor

gr2m commented Dec 1, 2018

I don’t think that adding something to @octokit/endpoint.js package.json is the right fix, there must be a better way. Maybe others run into the problem with webpack / deepmerge before and found a better workaround?

@brunolemos
Copy link

Side note: deepmerge readme points to this webpack issue webpack/webpack#6584

@brunolemos
Copy link

Maybe you can use a fork with these changes: TehShrike/deepmerge#124

@nonoroazoro
Copy link
Author

nonoroazoro commented Dec 1, 2018

@brunolemos Maybe adding the alias is the best workaround for now, and it looks like forward compatible.

@gr2m gr2m transferred this issue from octokit/octokit.js Dec 1, 2018
@gr2m
Copy link
Contributor

gr2m commented Dec 1, 2018

I moved the issue to @octokit/endpoint.js as it seems to be the origin of the problem

@gr2m
Copy link
Contributor

gr2m commented Dec 1, 2018

I was able to reproduce the problem, the build files attached to the releases throw the same error: https://github.com/octokit/endpoint.js/releases

It would be good to add a test that runs with the built file

@octokitbot
Copy link
Collaborator

🎉 This issue has been resolved in version 3.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nonoroazoro
Copy link
Author

Great job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants