You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I noticed that can't run some code built for Node.js target. I caught the following error:
/home/dmitriy/git/jdim/parcel-winston/src/index.ts:13
new winston.transports.File({ filename: `./error.log`, level: 'error' }),
^
TypeError: Class constructor File cannot be invoked without 'new'
at Object.<anonymous> (/home/dmitriy/git/jdim/parcel-winston/src/index.ts:13:28)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
According to this answer, you need transpile typescript for modern Node.js target to ES6 and newer.
Modern Node.js versions support ES6 classes, there is no need to transpile them.
Maybe you can read target from tsconfig.json.
馃敠 Context
馃捇 Code Sample
Code fragment:
import"source-map-support/register";importwinstonfrom'winston';constlogger=winston.createLogger({level: 'info',format: winston.format.json(),defaultMeta: {service: 'user-service'},transports: [//// - Write all logs with level `error` and below to `error.log`// - Write all logs with level `info` and below to `combined.log`// More about levels: https://github.com/winstonjs/winston#loggingnewwinston.transports.File({filename: `./error.log`,level: 'error'}),newwinston.transports.File({filename: `./combined.log`}),newwinston.transports.Console({format: winston.format.simple(),}),],});exportdefaultlogger;
Also, I've created a tiny repository, so you can reproduce this on your local machine
馃悰 bug report
Hello, I noticed that can't run some code built for Node.js target. I caught the following error:
But if I compile it with
tsc
it works.馃帥 Configuration (.babelrc, package.json, cli command)
package.json:
I am using the following scripts:
npm run build
npm run app
And I see the error.
But I can run it after:
npm run build.tsc
npm run app.tsc
You'll see no errors, and two log files in the project folder will be created.
馃 Expected Behavior
Build runs in Node.js without errors.
馃槸 Current Behavior
馃拋 Possible Solution
https://stackoverflow.com/questions/50203369/class-constructor-cannot-be-invoked-without-new-typescript-with-commonjs
According to this answer, you need transpile typescript for modern Node.js target to ES6 and newer.
Modern Node.js versions support ES6 classes, there is no need to transpile them.
Maybe you can read target from tsconfig.json.
馃敠 Context
馃捇 Code Sample
Code fragment:
Also, I've created a tiny repository, so you can reproduce this on your local machine
https://github.com/jdim/parcel-winston
馃實 Your Environment
The text was updated successfully, but these errors were encountered: