繁体   English   中英

如何将@google-cloud/logging 与 Webpack、Babel 和 Typescript 一起使用?

[英]How do I use @google-cloud/logging with Webpack, Babel, and Typescript?

我正在使用这个例子来开始,当我运行我的应用程序时我遇到了这个错误:

Failed to compile.
Module parse failed: Unexpected token (39:35)
api/utils/logger.ts
File was processed with these loaders:
 * ../.yarn/__virtual__/@pmmmwh-react-refresh-webpack-plugin-virtual-216e5b16fb/0/cache/@pmmmwh-react-refresh-webpack-plugin-npm-0.5.1-c36df928dc-e6d6d35013.zip/node_modules/@pmmmwh/react-refresh-webpack-plugin/loader/index.js
 * ../.yarn/__virtual__/source-map-loader-virtual-18915eaf0a/0/cache/source-map-loader-npm-3.0.0-2c53c811b5-c4459cef5a.zip/node_modules/source-map-loader/dist/cjs.js
You may need an additional loader to handle the result of these loaders.
| }
| 
> async function quickstart(projectId: string, logName: string) {
|   // Creates a client
|   const logging = new Logging({ projectId });

我假设它是我需要添加到 webpack.config.ts 的加载程序,但我不确定那会是什么。 很难尝试使用 @google-cloud/logging 和 Webpack 或 Typescript 来研究我的错误。

编辑:我正在为这个项目使用 monorepo(纱线工作区)。 出现上述错误是因为我的 function 在一个工作区中使用 @google-cloud/logging,并且在另一个工作区中被调用。 我应该能够让它工作(?),但不确定。 我刚刚将 function 移到调用它的工作区中,错误就消失了。

既然我做了那个动作,我在使用 Webpack5 时遇到了一个错误。 几个示例错误:

➤ YN0000: ERROR in ../.yarn/cache/teeny-request-npm-7.1.3-d7a7a2dac2-81f27b1ebe.zip/node_modules/teeny-request/build/src/agents.js 23:14-28
➤ YN0000: Module not found: Error: Can't resolve 'url' in 'C:\Users\jwentling\Documents\GitHub\ui-mui\.yarn\cache\teeny-request-npm-7.1.3-d7a7a2dac2-81f27b1ebe.zip\node_modules\teeny-request\build\src'
➤ YN0000:
➤ YN0000: BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
➤ YN0000: This is no longer the case. Verify if you need this module and configure a polyfill for it.
➤ YN0000:
➤ YN0000: If you want to include a polyfill, you need to:
➤ YN0000:       - add a fallback 'resolve.fallback: { "url": require.resolve("url/") }'
➤ YN0000:       - install 'url'
➤ YN0000: If you don't want to include a polyfill, you can use an empty module like this:
➤ YN0000:       resolve.fallback: { "url": false }

➤ YN0000: ERROR in ../.yarn/cache/gtoken-npm-5.3.1-d316026d7b-7746679027.zip/node_modules/gtoken/build/src/index.js 10:11-24
➤ YN0000: Module not found: Error: Can't resolve 'fs' in '..\.yarn\cache\gtoken-npm-5.3.1-d316026d7b-7746679027.zip\node_modules\gtoken\build\src'

据我了解,我需要使 Webpack5 包含用于 node.js 核心模块的 polyfill,但我不知道如何以我对 Webpack 的有限知识来做到这一点。

如果需要更多信息,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM