Typescript/include issues in Webpack 4 project
Bartel-C8 opened this issue · 4 comments
Describe the bug
I have troubles using this module in my (outdated) webpack 4 project (due to other dependencies).
To Reproduce
Currently I am at
import { Core } from "mdns-listener-advanced";
import { emittedEvent } from "mdns-listener-advanced/dist/esm/types";
import { Device } from "mdns-listener-advanced/dist/types/types.d";
Expected behavior
I think it's best to also export the typescript type definitions (https://github.com/aminekun90/mdns_listener_advanced/blob/master/src/types.ts) in https://github.com/aminekun90/mdns_listener_advanced/blob/master/src/index.ts ?
This makes it easier, and in one place to be able to include all needed definitions.
I also seem to have problems with the emittedEvent
"type".
https://github.com/aminekun90/mdns_listener_advanced/blob/master/src/types.ts#L25
As it is a "normal" exposed object, its type declaration and its actual value end up in 2 places.
Why not use a (string) enum type for this? Seems a much better fit. And fixes my problem as well...
(https://www.typescriptlang.org/docs/handbook/enums.html#string-enums)
Desktop (please complete the following information):
- OS: [e.g. iOS] macOS
- Browser [e.g. chrome, safari]: Electron + Webpack 4
Additional info
Search tags:
Module parse failed: Unexpected token (2:7)
You may need an appropriate loader to handle this file type
Module not found: Error: Can't resolve
Thanks!
Thanks for the issue I'll be looking into it, getting back to you asap
Hello @Bartel-C8 I reproduced Your error in a simple webpack 4 project I've used this simple webpack.config
a fix is on it's way on version 3.2.6
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = {
mode: 'production',
entry: './example.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
externals: {
'mdns-listener-advanced': 'commonjs mdns-listener-advanced'
},
resolve: {
extensions: ['.js']
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: 5,
compress: {
warnings: false,
drop_console: true,
drop_debugger: true
},
output: {
comments: false,
beautify: false
}
}
})
]
}
};
Fix is available can you check if the latest version fixes your issue @Bartel-C8
Works! Thank you very much.
Went from:
import { Core } from "mdns-listener-advanced";
import * as mdnsTypes from "mdns-listener-advanced/dist/esm/types";
import { Device, emittedEvent as emittedEventType } from "mdns-listener-advanced/dist/types/types.d";
const emittedEvent: typeof emittedEventType = mdnsTypes.emittedEvent;
To
import { Core, EmittedEvent, Device } from "mdns-listener-advanced";