Burhan
Burhan

Reputation: 41

Digital Ocean Spaces TypeError [ERR_INVALID_URL]: Invalid URL

I am creating a Shopify app in the express on the local and getting this error. The same code is working when I use this app on the server. I don't know why is this not working in the local environment.

I am using Digital Ocean Spaces, Node.js v17.0.1, @aws-sdk/client-s3 v3.171.0.

import { S3 } from "@aws-sdk/client-s3";
import dotenv from "dotenv";

dotenv.config();

const s3Client = new S3({
    endpoint: process.env.SPACES_ENDPOINT,
    region: process.env.SPACES_REGION,
    credentials: {
        accessKeyId: process.env.SPACES_KEY,
        secretAccessKey: process.env.SPACES_SECRET,
    },
});

export default s3Client;

I have already placed valid env variables in the .env file.

Here is the error

burhan@burhan:/shopifynode$ shopify app serve
✓ ngrok tunnel running at https://ebb6-2401-4900-1c02-5a90-982c-9e83-1b5e-b9ee.ngrok.io, with account [email protected]
✓ .env saved to project root

⭑ To install and start using your app, open this URL in your browser:
https://ebb6-2401-4900-1c02-5a90-982c-9e83-1b5e-b9ee.ngrok.io/login?shop=my-app-staging.myshopify.com

Running server…

> dev
> cross-env NODE_ENV=development nodemon server/index.js --watch ./server

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): server/**/*

[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server/index.js`
node:internal/errors:464
   ErrorCaptureStackTrace(err);
   ^

TypeError [ERR_INVALID_URL]: Invalid URL
   at new NodeError (node:internal/errors:371:5)
   at onParseError (node:internal/url:552:9)
   at new URL (node:internal/url:632:5)
   at parseUrl (/shopifynode/node_modules/@aws-sdk/url-parser/dist-cjs/index.js:7:38)
   at resolveEndpointsConfig (/shopifynode/node_modules/@aws-sdk/config-resolver/dist-cjs/endpointsConfig/resolveEndpointsConfig.js:14:87)
   at new S3Client (/shopifynode/node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js:22:72)
   at new S3 (/shopifynode/node_modules/@aws-sdk/client-s3/dist-cjs/S3.js:98:1)
   at file:///shopifynode/server/helpers/s3-client.js:6:18
   at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
   at async Promise.all (index 0) {
 input: '"https://fra1.digitaloceanspaces.com"',
 code: 'ERR_INVALID_URL'
}

Node.js v17.0.1
[nodemon] app crashed - waiting for file changes before starting...

Upvotes: 4

Views: 1986

Answers (1)

Jan Paepke
Jan Paepke

Reputation: 2027

just a guess here, but I stumbled accross the same issue when migrating from aws-sdk2 to aws-sdk3: Seems v2 allowed for the endpoint to not include a protocol. in v3 it definitely needs it. Check your env var and maybe prefix it with 'https://'.

Upvotes: 9

Related Questions