react-notion-x icon indicating copy to clipboard operation
react-notion-x copied to clipboard

'Uncaught ReferenceError: process is not defined' error with Vite

Open raonsol opened this issue 2 years ago • 2 comments
trafficstars

Description

Enviroment: Vite + Typescript + SWC

When I tried to create new NotionAPI object, vite throws an error.

import { NotionAPI } from "notion-client";
const notion = new NotionAPI();
// Uncaught ReferenceError: process is not defined

I think it is related with package @szmarczak/http-timer, which uses code that implicitly gets node version by process.versions.node. Vite does not allow importing env variables with process object. (https://vitejs.dev/guide/env-and-mode.html)

raonsol avatar Jul 17 '23 13:07 raonsol

any chance you solved this problem? I faced same one and I tried npm install node-libs-browser and import it in notion-client.js but didn't work. it passed first error point but occured at below line var nodejsMajorVersion = Number(process.versions.node.split(".")[0]);

GEOkettle avatar May 01 '24 12:05 GEOkettle

@raonsol FYI, I tried to solve it with Pollypill and managed it but that wasn't a problem. even if you solve that problem you would face the CORS issue. this "process" and "CORS" occurred because we tried to call the notion's API from the client side so I installed notion-client on the node side and it worked fine

DOC says:

  • Notion's API should not be called from client-side browsers due to CORS restrictions. notion-client is compatible with Node.js and Deno.

GEOkettle avatar May 02 '24 04:05 GEOkettle