When running webpack on a project that includes the winston package, several warnings are generated. This is because webpack automatically includes non-javascript files due to a lazy-loading mechanism in a dependency called logform.
The issue arises when webpack includes all files, including README.md files, and tries to process them with Typescript. Despite attempting to use webpack's ContextReplacementPlugin, it still doesn't resolve the problem.
In an attempt to address this, I added the following to my plugins list in webpack.config.js:
new webpack.ContextReplacementPlugin(/logform/, /(.*)\.js/)
Although this eliminates the warnings during build time, at runtime, an error occurs where webpack is unable to require one of those files.
So what exactly am I missing here?
Warnings Produced by Webpack
WARNING in ./node_modules/logform/index.d.ts
Module build failed: Error: Typescript emitted no output for //Users/aneil/code/project/node_modules/logform/index.d.ts.
You should not need to recompile .ts files in node_modules.
Please contact the package author to advise them to use --declaration --outDir.
More https://github.com/Microsoft/TypeScript/issues/12358
at successLoader (/Users/aneil/code/project/node_modules/ts-loader/dist/index.js:39:15)
at Object.loader (/Users/aneil/code/project/node_modules/ts-loader/dist/index.js:21:12)
@ ./node_modules/logform sync ^\.\/.*$
@ ./node_modules/logform/index.js
@ ./node_modules/winston/lib/winston.js
@ ./src/logger.ts
@ ./src/services/pipeline/handlers.ts
<!-- Other warning messages go here -->
The Runtime errors after adding the ContextReplacementPlugin can be seen below.
<script>
Serverless: GET /api (λ: GraphQLPlayground)
Serverless: The first request might take a few extra seconds
Serverless: Error while loading GraphQLPlayground
[ 'Error: Cannot find module "./combine".',
'at webpackContextResolve (webpack:///./node_modules/logform_sync_(.*)\\.js?:39:11)',
'at webpackContext (webpack:///./node_modules/logform_sync_(.*)\\.js?:32:11)',
'at Function.get (webpack:///./node_modules/logform/index.js?:27:101)',
'at eval (webpack:///./src/logger.ts?:34:20)',
</script>