cloud icon indicating copy to clipboard operation
cloud copied to clipboard

Next.js: Display a clearer error message if you try to import Cloud SDK in the front-end

Open taylorpreston opened this issue 3 years ago • 6 comments

Hey!

I'm getting this error when trying to import the storage module from serverless cloud.

import { storage } from "@serverless/cloud";

Anyone else having this issue?

This is the output in the terminal.

SyntaxError: Unexpected string in JSON at position 365
    at Object.parse [as parseJSON] (<anonymous>)
    at Object.loadSync (file:///opt/nodejs/cloud/worker.mjs:7:4492)
    at Qt.runLoaderSync (file:///opt/nodejs/cloud/worker.mjs:7:3670)
    at Qt.loadSync (file:///opt/nodejs/cloud/worker.mjs:7:4598)
    at Bn.loadEntrypoint (file:///opt/nodejs/cloud/worker.mjs:27:4265)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 0)
    at Bn.load (file:///opt/nodejs/cloud/worker.mjs:27:4409)
    at Bn.handler (file:///opt/nodejs/cloud/worker.mjs:27:5295)
    ```

taylorpreston avatar Apr 18 '22 15:04 taylorpreston

Hi Taylor, that indicates a parsing error reading your package.json file. Can you post the contents here so I can take a look?

rschick avatar Apr 18 '22 15:04 rschick

@rschick here's my package.json 👍

{
  "name": "nextjs",
  "version": "0.1.0",
  "description": "Serverless Cloud Next.js template",
  "scripts": {
    "cloud:dev": "next dev",
    "cloud:build": "next build",
    "lint": "next lint"
  },
  "dependencies": {
    "@nextui-org/react": "^1.0.8-beta.5",
    "axios": "^0.26.1",
    "next": "12.1.0",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "@serverless/cloud": "^2.7.3",
    "eslint": "8.11.0",
    "prettier": "^2.6.2",
    "eslint-config-next": "12.1.0",
    "swr": "^1.2.2"
  },
  "serverless": {
    "app": "serverless-cloud",
    "org": "taylorpreston"
  }
}

taylorpreston avatar Apr 19 '22 14:04 taylorpreston

Thanks @taylorpreston, that looks ok to me. Can you send me your org and instance name? You can DM me in Slack: https://serverless-contrib.slack.com/join/shared_invite/zt-d5qzowja-pnOerTzAIZUrN18hWYUIHA

rschick avatar Apr 19 '22 15:04 rschick

Hey @rschick I'm getting a "This link is no longer active" message on the slack invite. 🤷

taylorpreston avatar Apr 19 '22 17:04 taylorpreston

Sorry about that, try https://www.serverless.com/slack

rschick avatar Apr 19 '22 17:04 rschick

This was caused by importing the Cloud SDK into a front-end component, which currently isn't supported.

I'm going to keep this open until we improve the error message and documentation around this.

rschick avatar Apr 20 '22 15:04 rschick