I want to use mssql in a vue-electron project. I installed mssql with npm. When i want to run the app, i get the following error:
ERROR Failed to compile with 2 errors
error in ./node_modules/mssql/lib/tedious/connection-pool.js
Module parse failed: Unexpected token (39:63)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| cfg.options.database = cfg.options.database || this.config.database
| cfg.options.port = cfg.options.port || this.config.port
> cfg.options.connectTimeout = cfg.options.connectTimeout ?? this.config.connectionTimeout ?? this.config.timeout ?? 15000
| cfg.options.requestTimeout = cfg.options.requestTimeout ?? this.config.requestTimeout ?? this.config.timeout ?? 15000
| cfg.options.tdsVersion = cfg.options.tdsVersion || '7_4'
@ ./node_modules/mssql/lib/tedious/index.js 4:23-51
@ ./node_modules/mssql/index.js
@ ./src/modules/db.js
@ ./src/background.js
@ multi ./src/background.js
error in ./node_modules/mssql/lib/tedious/request.js
Module parse failed: Unexpected token (446:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| const req = new tds.Request(command, err => {
| // tedious v15 has started using AggregateErrors to wrap multiple errors into single error objects
> (err?.errors ? err.errors : [err]).forEach((e, i, { length }) => {
| // to make sure we handle no-sql errors as well
| if (e && (!errors.length || (errors.length && errors.length >= length && e.message !== errors[errors.length - length + i].message))) {
@ ./node_modules/mssql/lib/tedious/index.js 6:16-36
@ ./node_modules/mssql/index.js
@ ./src/modules/db.js
@ ./src/background.js
@ multi ./src/background.js
Can someone please help me?
For future reference and for people landing here through a search engine, this error is probably related to using a version of node < 14. Upgrade to the latest LTS using NVM or some other method and you should be good to go.
Edit: Since the community bot thinks that "others cannot confirm that my answer is correct" and therefore my answer could be improved, you can try the following: install NodeJS < v14, try including the mssql library and you will get the error that is mentioned in the question.
If you want more information on why this error happens, it's because the node version that you are running does not support null coalescing (which means that you are running node < v14).
You can find similar (closed) issues in the library's GitHub issue queue here and here.