Sql-parser for production is missing

Hello,

I want to use sql-parser for my VueJs3 project.
Currently I’m using “sql-parser”: “^0.5.0” for developement.
But, after I built my app for production, sql-parser is missing. I received this error:
Uncaught ReferenceError: sql is not defined
Because it’s looking for sql = require(’./lib/sql_parser’)

How can I save this dependencie?

Thnx in advance!

The issue you’re encountering is likely caused by a missing or incorrect import statement for the sql-parser library in your code. Make sure that you have correctly imported the library in the component or file where you are using it, and that it is correctly listed as a dependency in your project’s package.json file.

If you’re using a build tool like Webpack, also make sure that the library is included in your build process, and that the required dependencies are installed.

Here’s an example import statement that you can use in your Vue component:

import sqlParser from 'sql-parser';

And make sure that sql-parser is installed by running npm install sql-parser .

Hi @innenrinde
First, make sure that the library is included and that the required dependencies are installed.
Install node-sql-parser using npm i node-sql-parser or yarn add node-sql-parser command.

In package.json
“dependencies”: {
“sql-parser”: “^0.5.0”
}

In my component:
import sqlParser from 'sql-parser';

En dev mode it works.

After npm run build, on production:
sql = require(’./lib/sql_parser’)
for(var key in sql) {
exports[key] = sql[key]
}

With error: Uncaught ReferenceError: sql is not defined

Without import sqlParser from ‘sql-parser’; I have no errors.

The error is occurring because the sql variable is not defined before it is used in the loop that exports its properties. This is likely because the import statement is being transformed by a tool like Babel or Webpack to a CommonJS-style require statement that only works in a CommonJS environment (such as Node.js).

In the production environment, the code is being run in a browser, which does not have a CommonJS environment. To fix the issue, try using a different way of importing the sql-parser package that is compatible with the browser environment, such as using an ECMAScript module import:

import * as sql from 'sql-parser';