在包含winston的项目上运行webpack会产生许多警告(见下文)。由于依赖项中的延迟加载机制,Webpack会自动包含非javascript文件。 你可以看到这里发生了什么 - 请参阅exposeFormat函数:https://github.com/winstonjs/logform/blob/master/index.js
Webpack无法确定要包含哪些文件,因此它包含所有文件,包括README.md文件,并尝试使用Typescript处理它们。我知道webpack的ContextReplacementPlugin应该对我有帮助,但是我无法让它工作。
我已经尝试将其添加到webpack.config.js中的插件列表中:
new webpack.ContextReplacementPlugin(/logform/, /(.*)\.js/)
我认为这应该包含文件夹中的所有.js文件。这在构建时消除了警告,但在运行时,我从webpack收到错误,表明尝试要求其中一个文件失败。
我做错了什么?
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
WARNING in ./node_modules/logform/CHANGELOG.md
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| # CHANGELOG
|
| ### 1.4.2
@ ./node_modules/logform sync ^\.\/.*$
@ ./node_modules/logform/index.js
@ ./node_modules/winston/lib/winston.js
@ ./src/logger.ts
@ ./src/services/pipeline/handlers.ts
WARNING in ./node_modules/logform/README.md
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| # logform
|
| An mutable object-based log format designed for chaining & objectMode streams.
@ ./node_modules/logform sync ^\.\/.*$
@ ./node_modules/logform/index.js
@ ./node_modules/winston/lib/winston.js
@ ./src/logger.ts
@ ./src/services/pipeline/handlers.ts
WARNING in ./node_modules/logform/LICENSE
Module parse failed: Unexpected token (1:4)
You may need an appropriate loader to handle this file type.
| MIT License
|
| Copyright (c) 2017 Charlie Robbins & the Contributors.
@ ./node_modules/logform sync ^\.\/.*$
@ ./node_modules/logform/index.js
@ ./node_modules/winston/lib/winston.js
@ ./src/logger.ts
@ ./src/services/pipeline/handlers.ts
添加ContextReplacementPlugin 后, 运行时错误
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)',
答案 0 :(得分:0)
我认为解决此问题的最佳方法是直接在logform库中解决问题,因此我提交了此PR:https://github.com/winstonjs/logform/pull/24