0

I unfortunately can not any reliable documentation on how to use an npm package in BigQuery. I want to use the package isitblocked in BigQuery and parse the URLs in my tables through the library.

I only found this blog, but I can't re-procedure the steps there and get the following error while using webpack:

`assets by status 390 bytes [cached] 1 asset ./index.ts 2.43 KiB [built] [code generated] [1 error] WARNING in configuration The 'mode' option has not been set, webpack will fallback to > 'production' for this value. Set 'mode' option to 'development' or 'production' to enable > defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/configuration/mode/ ERROR in ./index.ts 1:16 Module parse failed: Unexpected token (1:16) 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 import envPaths = require("env-paths"); | import Listr = require("listr"); | import fs = require("fs-extra"); \

The package I try to install is isitblocked.

  • This is a webpack issue. `npx webpack --config webpack.config.js --mode none` with setting the mode the warning vanish. However, in this example the filename is given wrong and the `creditcard-generator.js` want to provide a function `module.exports.GenCC` instead of `creditcard_generator.GenCC`. – Samuel Mar 29 '22 at 18:22
  • The package npmjs.com/package/@sammacbeth/isitblocked is ts and not js. The webpack has to be set to this https://webpack.js.org/guides/typescript/ . Could you please provide your `webpack.config.js` file to see where the error is. Please check before that this packages does not fetch data from other sources, e.g. reading or query of blocklist. This is not allowed by BigQuery: https://stackoverflow.com/questions/34633292/making-api-call-as-part-of-udf-in-bigquery-possible – Samuel Mar 30 '22 at 17:14

1 Answers1

0

I did it step by step in the google Shell and it prompted to install the webpack. Please include the mode none or production

npx webpack --config webpack.config.js --mode none

Then upload the file under dist and edit the BigQuery query to:

CREATE TEMP FUNCTION get_rand_card_number()
RETURNS STRING
LANGUAGE js   
OPTIONS (
library=["gs://***your*bucket*name***/creditcard-generator.js"]
)
AS r"""
return webpackNumbers.GenCC("Amex"); # Still wrong function name
""";

CREATE TEMP FUNCTION get_rand_id()
RETURNS STRING
LANGUAGE js
AS r"""
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 4 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(4);
});
""";


SELECT 
     x,
     get_rand_id() as unique_id, 
     get_rand_card_number() as credit_card_number 
FROM 
   unnest(generate_array(1,100,1)) x
Samuel
  • 2,923
  • 1
  • 4
  • 19
  • I'm so sorry for that but I forgot to mention the package I try to install. It's https://www.npmjs.com/package/@sammacbeth/isitblocked do you think it's also should be possible? – Moruk Turu Mar 30 '22 at 07:31
  • I get now `./index.ts 2.43 KiB [built] [code generated] [1 error] ERROR in ./index.ts 1:16 Module parse failed: Unexpected token (1:16) 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 > import envPaths = require("env-paths"); | import Listr = require("listr"); | import fs = require("fs-extra"); ` – Moruk Turu Mar 30 '22 at 07:34