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
i'm trying to build my index.js in a single contained file. That's working very well with commonjs, but when i try to build with module type, when i run the code it doesn't work.
I run the command:
ncc build index.js -m
This is my test code:
import{createLogger,formatas_format,transportsas_transports}from'winston';constlogger=createLogger({level: 'info',format: _format.json(),defaultMeta: {service: 'user-service'},transports: [//// - Write all logs with importance level of `error` or less to `error.log`// - Write all logs with importance level of `info` or less to `combined.log`//new_transports.File({filename: 'error.log',level: 'error'}),new_transports.File({filename: 'combined.log'}),],});//// If we're not in production then log to the `console` with the format:// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `//if(process.env.NODE_ENV!=='production'){logger.add(new_transports.Console({format: _format.simple(),}));}
Then, when i run node dist/index.js it throws this error:
file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14506
module.exports = require("util");
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and 'file:///C:/Users/user/source/repos/app/scripts/dist/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at 3837 (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14506:1)
at __nccwpck_require__ (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14546:42)
at 5825 (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:41:12)
at __nccwpck_require__ (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14546:42)
at 1251 (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:770:14)
at __nccwpck_require__ (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14546:42)
at 3605 (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:5264:16)
at __nccwpck_require__ (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14546:42)
at 7829 (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:5695:23)
at __nccwpck_require__ (file:///C:/Users/user/source/repos/app/scripts/dist/index.js:14546:42)
Does anyone has this problem before?
The text was updated successfully, but these errors were encountered:
i'm trying to build my
index.js
in a single contained file. That's working very well withcommonjs
, but when i try to build with module type, when i run the code it doesn't work.I run the command:
This is my test code:
This is my
package.json
:Then, when i run
node dist/index.js
it throws this error:Does anyone has this problem before?
The text was updated successfully, but these errors were encountered: