sveltejs / kit

web development, streamlined
https://svelte.dev/docs/kit
MIT License
18.64k stars 1.92k forks source link

sveltekit(vite build failed) - not able to use winston logging toolkit - string_decoder/' is not supported #7190

Closed kpopovic closed 2 years ago

kpopovic commented 2 years ago

Describe the bug

Hello,

when import * as winston from 'winston'; is imported the app breaks because of string_decoder/' is not supported error. Is winston possible to be used in sveltekit ? How to configure it? Is any logging npm package which writes logs to file possible to use in sveltekit ?

Reproduction

stackblitz example

  1. npm run build
  2. node build/index.js // see Logs below for errors

Logs

❯ node build/index.js
Error: Directory import '/home/projects/sveltejs-kit-template-default-uoasnv/node_modules/string_decoder/' is not supported resolving ES modules imported from /home/projects/sveltejs-kit-template-default-uoasnv/build/server/chunks/hooks.server-63a1c264.js
Did you mean to import string_decoder/lib/string_decoder.js?
    at async ESMLoader.import (https://sveltejs-kit-template-default-uoasnv.w.staticblitz.com/blitz.c3f3eab0760382367e86f2a862c18516376c36f4.js:6:1209286)
    at async i.loadESM (https://sveltejs-kit-template-default-uoasnv.w.staticblitz.com/blitz.c3f3eab0760382367e86f2a862c18516376c36f4.js:6:246622)
    at async handleMainPromise (https://sveltejs-kit-template-default-uoasnv.w.staticblitz.com/blitz.c3f3eab0760382367e86f2a862c18516376c36f4.js:6:989295) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///home/projects/sveltejs-kit-template-default-uoasnv/node_modules/string_decoder/'
}

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.80 
    @sveltejs/adapter-node: * => 1.0.0-next.96 
    @sveltejs/kit: next => 1.0.0-next.511 
    svelte: ^3.46.0 => 3.50.1 
    vite: ^3.1.0 => 3.1.6

Severity

blocking all usage of SvelteKit

Additional Information

No response

Conduitry commented 2 years ago

The last time I used it in an app, the Winston package did some really wild stuff that made it impossible to bundle. I'd suggest moving it to a prod dependency of your app.

kpopovic commented 2 years ago

prod dependency

Hello,

the "same" thing also happens with mysql2 package...

mysql-stackblitz

"devDependencies": {
    "@fontsource/fira-mono": "^4.5.0",
    "@neoconfetti/svelte": "^1.0.0",
    "@sveltejs/adapter-auto": "next",
    "@sveltejs/adapter-node": "*",
    "@sveltejs/kit": "next",
    "@types/cookie": "^0.5.1",
    "knex": "^2.3.0",
    "mysql2": "^2.3.3",
    "prettier": "^2.6.2",
    "prettier-plugin-svelte": "^2.7.0",
    "svelte": "^3.46.0",
    "svelte-check": "^2.7.1",
    "typescript": "^4.7.4",
    "vite": "^3.1.0"
},

'better-sqlite3' is imported by better-sqlite3?commonjs-external, but could not be resolved – treating it as an external dependency 'tedious' is imported by tedious?commonjs-external, but could not be resolved – treating it as an external dependency 'mysql' is imported by mysql?commonjs-external, but could not be resolved – treating it as an external dependency 'oracledb' is imported by oracledb?commonjs-external, but could not be resolved – treating it as an external dependency 'pg' is imported by pg?commonjs-external, but could not be resolved – treating it as an external dependency 'pg-query-stream' is imported by pg-query-stream?commonjs-external, but could not be resolved – treating it as an external dependency 'sqlite3' is imported by sqlite3?commonjs-external, but could not be resolved – treating it as an external dependency Circular dependency: node_modules/mysql2/index.js -> node_modules/mysql2/lib/connection.js -> node_modules/mysql2/promise.js -> node_modules/mysql2/index.js Circular dependency: node_modules/mysql2/index.js -> node_modules/mysql2/lib/pool.js -> node_modules/mysql2/index.js Circular dependency: node_modules/mysql2/index.js -> node_modules/mysql2/lib/pool.js -> node_modules/mysql2/lib/pool_connection.js -> node_modules/mysql2/index.js ✔ done

when I add all "missing" dependencies, at the end I get also ** string_decoder/' is not supported.

kpopovic commented 2 years ago

@Conduitry Now it seams to work, I have placed winston packages to prod dependency section. Will try it also for mysql2 dependency to see will it also work.

{ "name": "kit-template-default", "version": "0.0.1", "scripts": { "dev": "vite dev", "build": "vite build", "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json --watch", "lint": "prettier --plugin-search-dir . --check .", "format": "prettier --plugin-search-dir . --write ." }, "devDependencies": { "@fontsource/fira-mono": "^4.5.0", "@neoconfetti/svelte": "^1.0.0", "@sveltejs/adapter-auto": "next", "@sveltejs/adapter-node": "*", "@sveltejs/kit": "next", "@types/cookie": "^0.5.1", "jose": "^4.10.0", "luxon": "^3.0.4", "prettier": "^2.6.2", "prettier-plugin-svelte": "^2.7.0", "svelte": "^3.46.0", "svelte-check": "^2.7.1", "typescript": "^4.7.4", "vite": "^3.1.0" }, "type": "module", "dependencies": { "winston": "^3.8.2", "winston-daily-rotate-file": "^4.7.1" } }

kpopovic commented 2 years ago

@Conduitry I confirm that mysql2 package is also build properly when placed to prod dependency in package.json file. How to know then when to place dependency to dev or prod section ? Just to check if buildwith adapter-node works or not ?

dominikg commented 2 years ago

@kpopovic we do not handle questions or support via github bugs. please start a discussion or ask on https://svelte.dev/chat in #questions

Closing here as putting winston in pkg.dependencies is the proper way to do it.