-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Type issues in webpack-merge #141
Comments
@sdc224 Can you try adding @types/webpack-dev-server to your project as it extends webpack's regular types with the Likely |
|
|
Ok, I'll check this better detail then. It might have to do with the way I wired I wonder if we should even go as far as to decouple |
Are you referring to this? import { Configuration } from "webpack";
import { merge as webpackMerge } from "webpack-merge";
import baseConfig from "./webpack.common";
import paths from "../paths";
import WebpackDevServer from "webpack-dev-server";
const config = <Configuration & WebpackDevServer.Configuration>(
webpackMerge(baseConfig, {
mode: "development",
devtool: "#inline-source-map",
devServer: {
port: 5000,
contentBase: paths.build,
compress: true,
open: true
}
})
);
export default config; |
@sdc224 Exactly. I haven't implemented the idea yet but it's the first thing that came to my mind. |
Yes, that's why it is still showing the issue. |
Can you tell me how it was working in |
@sdc224 That's a good question. Let me research a bit. |
@bebraw 😅. Are we going to get the fix in next release? |
Yup, I'll find some way. 👍 It looks like |
Ok thanks man, so quick responses 😄. Hoping to hear from you very soon. |
@sdc224 Can you set up a small repository that shows the type error? At least VS Code seems to find the types properly against a simple config. |
@sdc224 Here's my TS setup (no type errors): https://github.com/bebraw/webpack-merge-ts-debug . I imagine there's some difference I missed. |
@bebraw Yes man, the catch is in the below line written in "include": ["src", "types"] as your webpack config is outside of src, |
Thanks for the repository. I learned that if I set import { Configuration as WebpackConfiguration } from "webpack";
import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
} within webpack-merge type definition, it works. The problem is that this couples the utility with webpack-dev-server as well. I found the solution from DefinitelyTyped/DefinitelyTyped#27570 . I have to think more about this one. It's a little weird as |
Here's another solution. Add this bit to the configuration: import WebpackDevServer from "webpack-dev-server";
declare module "webpack" {
interface Configuration {
devServer?: WebpackDevServer.Configuration;
}
} The open question is why is this needed now? |
@sdc224 I noticed your It's important to set that for ts-node to work correctly. It feels like something else is missing as the dev server types aren't being applied with this change. |
@sdc224 Would I guess the other option would be to figure out why that webpack-dev-server configuration extension doesn't get applied in this particular case. It's tricky to say how to debug this, though. |
Sorry for so late reply, was occupied on some problems.
This is how I am doing right now 🤣 |
@bebraw That merge is not working for me |
I started a branch with the generic. See https://github.com/survivejs/webpack-merge/blob/feat/ts-generic/test/merge.test.ts#L16 . That said, it looks like webpack-dev-server is patching the type correctly even within this repository. I wonder if we're looking at a TypeScript configuration issue here? |
@TheGrimSilence Can you change from import WebpackMerge from 'webpack-merge'; to import * as WebpackMerge from 'webpack-merge'; or import { merge as WebpackMerge } from 'webpack-merge'; I had to change the exports to avoid |
What do you think? Should we raise in I wonder how it was working in |
Guys any update on this? |
Hi, I'm a bit stuck on this one as I'm not sure if the issue is on the typing side or something in TypeScript we don't understand. Likely external type definitions are more powerful as they can model a bit more. I bet it's something "obvious" we are missing. |
One thing I need to mention, I don't know any explanation for that, but for me it is right now working fine😅😅, I mean, working without any type errors |
Similar issue there. Today just made a fresh TSError: ⨯ Unable to compile TypeScript:
webpack.dev.ts:8:39 - error TS2349: This expression is not callable.
Type 'typeof import("/home/dzintars/code/front/.yarn/cache/webpack-merge-npm-5.0.9-c8179aa67c-7d31955ae5.zip/node_modules/webpack-merge/dist/index")' has no call signatures.
8 const config: webpack.Configuration = merge(common, {
at createTSError (/home/dzintars/code/front/.yarn/$$virtual/ts-node-virtual-37c47ab5ad/0/cache/ts-node-npm-8.10.2-b4fe5a56b0-cd6e023e07.zip/node_modules/ts-node/src/index.ts:434:12)
at reportTSError (/home/dzintars/code/front/.yarn/$$virtual/ts-node-virtual-37c47ab5ad/0/cache/ts-node-npm-8.10.2-b4fe5a56b0-cd6e023e07.zip/node_modules/ts-node/src/index.ts:438:19)
at getOutput (/home/dzintars/code/front/.yarn/$$virtual/ts-node-virtual-37c47ab5ad/0/cache/ts-node-npm-8.10.2-b4fe5a56b0-cd6e023e07.zip/node_modules/ts-node/src/index.ts:578:36)
at Object.compile (/home/dzintars/code/front/.yarn/$$virtual/ts-node-virtual-37c47ab5ad/0/cache/ts-node-npm-8.10.2-b4fe5a56b0-cd6e023e07.zip/node_modules/ts-node/src/index.ts:775:32)
at Module.m._compile (/home/dzintars/code/front/.yarn/$$virtual/ts-node-virtual-37c47ab5ad/0/cache/ts-node-npm-8.10.2-b4fe5a56b0-cd6e023e07.zip/node_modules/ts-node/src/index.ts:858:43)
at Module._extensions..js (internal/modules/cjs/loader.js:1277:10)
at Object.require.extensions.<computed> [as .ts] (/home/dzintars/code/front/.yarn/$$virtual/ts-node-virtual-37c47ab5ad/0/cache/ts-node-npm-8.10.2-b4fe5a56b0-cd6e023e07.zip/node_modules/ts-node/src/index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:1105:32)
at Function.external_module_.Module._load (/home/dzintars/code/front/.pnp.js:17771:14)
at Module.require (internal/modules/cjs/loader.js:1145:19) I have Yarn PnP greenfield setup there: » yarn why webpack-merge
└─ front@workspace:.
└─ webpack-merge@npm:5.0.9 (via npm:latest)
» node --version
v14.7.0
» npm --version
6.14.7
» yarn --version
2.1.1
» tsc --version
Version 3.9.7 Not sure which update exactly causes this. Will leave this comment. Have installed all required @types, etc. |
@dzintars Can you set up a small repository showcasing the error? Note that you should do I could expose |
@dzintars I added support for |
@bebraw Good morning. :) Thank you very much! Seems at least my issue is solved with 5.1.0. |
@dzintars Ok, cool. I think this issue is something else as webpack-dev-server doesn't seem to patch webpack type correctly for this specific case and it's still unclear why. |
Unable to use
devServer
property insidewebpack.config.ts
, when writing webpack configuration in TS file.webpack-merge
While I'm in
webpack-merge
v4 with@types/webpack-merge
, it was working fine. Now after updatingwebpack-merge
to 5, I have removed the@types/webpack-merge
(as perCHANGELOG
). After that it is throwing TS errorwebpack.config.dev.ts
The text was updated successfully, but these errors were encountered: