我正在使用 sveltekit 创建一个应用程序,目前正在添加日志记录。
使用winston 在后端非常简单,因为它几乎可以开箱即用。
但是我在前端导入它时遇到了一些问题。
我的代码很简单
<script>
import winston from 'winston';
import { Card } from '../components/issue/';
export let project;
</script>
但那个简单的片段似乎抛出了这个错误
500
process is not defined
ReferenceError: process is not defined
at node_modules/colors/lib/system/supports-colors.js (http://localhost:3000/node_modules/.vite/winston.js?v=b8878498:281:15)
at __require (http://localhost:3000/node_modules/.vite/chunk-JAKTRAE2.js?v=b8878498:6:44)
at node_modules/colors/lib/colors.js (http://localhost:3000/node_modules/.vite/winston.js?v=b8878498:714:28)
at __require (http://localhost:3000/node_modules/.vite/chunk-JAKTRAE2.js?v=b8878498:6:44)
at node_modules/colors/safe.js (http://localhost:3000/node_modules/.vite/winston.js?v=b8878498:850:18)
at __require (http://localhost:3000/node_modules/.vite/chunk-JAKTRAE2.js?v=b8878498:6:44)
at node_modules/logform/dist/colorize.js (http://localhost:3000/node_modules/.vite/winston.js?v=b8878498:881:18)
at __require (http://localhost:3000/node_modules/.vite/chunk-JAKTRAE2.js?v=b8878498:6:44)
at node_modules/logform/dist/levels.js (http://localhost:3000/node_modules/.vite/winston.js?v=b8878498:953:20)
at __require (http://localhost:3000/node_modules/.vite/chunk-JAKTRAE2.js?v=b8878498:6:44)
老实说,我真的不知道可能出了什么问题,除非它可能是服务器/客户端渲染的问题。
所以我想问题是:你可以在 sveltekit 项目中导入winston,如果可以的话怎么做?这个特定问题有什么解决方法吗?