docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Non-build ui js using window

Open godgege opened this issue 2 years ago • 1 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [X] I'm using the latest version of Docusaurus.
  • [ ] I have tried the npm run clear or yarn clear command.
  • [ ] I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • [ ] I have tried creating a repro with https://new.docusaurus.io.
  • [ ] I have read the console error message carefully (if applicable).

Description

Error: It looks like you are using code that should run on the client-side only. To get around it, try using one of: - <BrowserOnly> (https://docusaurus.io/docs/docusaurus-core/#browseronly) - ExecutionEnvironment (https://docusaurus.io/docs/docusaurus-core/#executionenvironment).

Reproducible demo

No response

Steps to reproduce

import {api_list, api_user} from "../../util/api"; //  use `axios` and `window.atob()`

class Content extends React.Component {
    componentDidMount() {
        api_list()
        api_user().then(response => {
            this.setState({})
        })
    }
}

Expected behavior

build success!

Actual behavior

What am I doing wrong, I can understand not being able to access the window, but I don't think I'm doing anything wrong.

Remove Window for a successful build

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • [ ] I'd be willing to fix this bug myself.

godgege avatar Jul 25 '24 23:07 godgege

The error message tells you exactly what to do. GH issues are not for support questions; please ask in one of our support channels instead.

Josh-Cena avatar Jul 25 '24 23:07 Josh-Cena