Bundling amazon-sp-api with webpack

Viewed 63

I'm, trying to generate a bundle from a javascript to get some requests from Amazon Selling Partner API. Actually, I have a mockup of a getOrders request which works in Node.js by using the [amazon-sp-api client package] (https://www.npmjs.com/package/amazon-sp-api#setting-credentials-from-environment-variables). As I need to get the script working in Oracle Netsuite, I would need to copy that script to the Netsuite account as a unique-file bundle. So, I have generated the bundle I need but it launches a TypeError when trying to execute it as a unique file with Node. Indeed, the error header looks like this:

    ...readdirSync(__dirname + '/resources').reduce((eps, ep) => {
       ^

TypeError: readdirSync is not a function

It appears to be some issue about my webpack.config.js as I'm using a basic config and it probably requires specific details to lead with the dependencies. There is a dependency I use in my script, which at once use third-party dependencies:

const SellingPartnerAPI = require('amazon-sp-api');

My webpack.config.js looks like this:

const path = require('path');
//const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  //This property defines where the application starts
  entry:'./app.js',
    
  //This property defines the file path and the file name which will be used for deploying the bundled file
  output:{
    path: path.join(__dirname, '/dist'),
    filename: 'get_orders.js'
  },

  //Setup loaders
  module: {
    rules: [
      {
        test: /\.js$/, 
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader'
        }
      }
    ]
  },
    
  // Setup plugin to use a HTML file for serving bundled js files
  plugins: [
  /*  new HtmlWebpackPlugin({
      template: './src/index.html'
    })*/
  ]

}

And the package.json is this:

{
  "name": "orders-importer-bundle",
  "version": "1.0.0",
  "description": "Project to create a test blundle to import orders from Amazon to Netsuite using SP-API and SuiteScript.",
  "main": "app.js",
  "scripts": {
    "pack": "webpack-dev-server --mode development --open --hot",
    "dev": "webpack --mode development",
    "build": "webpack --mode production",
    "start": "node ./app.js"
  },
  "repository": {
    "type": "git",
    "url": "main"
  },
  "keywords": [
    "webpack",
    "bundle",
    "netsuite",
    "amazon",
    "sp-api"
  ],
  "author": "Roberto Carlos Rodriguez",
  "license": "ISC",
  "dependencies": {
    "amazon-sp-api": "^0.7.1"
  },
  "devDependencies": {
    "@babel/cli": "^7.17.6",
    "@babel/core": "^7.17.7",
    "@babel/preset-env": "^7.16.11",
    "@babel/preset-react": "^7.16.7",
    "babel-core": "^6.26.3",
    "babel-loader": "^8.2.3",
    "html-webpack-plugin": "^5.5.0",
    "babel-preset-env": "^1.7.0",
    "webpack": "^5.70.0",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.7.4"
  }
}
0 Answers
Related