Repository: parse-community/Parse-SDK-JS

Issue #1766: Can't import parse in svelte
Created: 2023-02-12T18:36:04Z
New Issue Checklist


 I am not disclosing a vulnerability.
 I am not just asking a question.
 I have searched through existing issues.
 I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK. 

Issue Description

Steps to reproduce
$ npm create svelte@latest my-app
$ # -> svbeltekit demo app, using typescript
$ # -> no, no, no, no
$ cd my-app
$ npm i
$ npm i --save parse@4.0.0-alpha.12

Now add this line e.g. to routes/Header.svelte:
import Parse from "parse/node";
And launch the site, check the JS console.
Actual Outcome
start.js:39 Uncaught (in promise) TypeError: Class extends value undefined is not a constructor or null
    at node_modules/parse/lib/node/LiveQuerySubscription.js (LiveQuerySubscription.js:100:42)
    at __require2 (chunk-7FP5O474.js?v=548792af:10:50)
    at node_modules/parse/lib/node/LiveQueryClient.js (LiveQueryClient.js:10:53)
    at __require2 (chunk-7FP5O474.js?v=548792af:10:50)
    at node_modules/parse/lib/node/ParseLiveQuery.js (ParseLiveQuery.js:8:47)
    at __require2 (chunk-7FP5O474.js?v=548792af:10:50)
    at node_modules/parse/lib/node/Parse.js (Parse.js:255:19)
    at __require2 (chunk-7FP5O474.js?v=548792af:10:50)
    at node_modules/parse/node.js (node.js:1:18)
    at __require2 (chunk-7FP5O474.js?v=548792af:10:50)
node_modules/parse/lib/node/LiveQuerySubscription.js	@	LiveQuerySubscription.js:100
__require2	@	chunk-7FP5O474.js?v=548792af:10
node_modules/parse/lib/node/LiveQueryClient.js	@	LiveQueryClient.js:10
__require2	@	chunk-7FP5O474.js?v=548792af:10
node_modules/parse/lib/node/ParseLiveQuery.js	@	ParseLiveQuery.js:8
__require2	@	chunk-7FP5O474.js?v=548792af:10
node_modules/parse/lib/node/Parse.js	@	Parse.js:255
__require2	@	chunk-7FP5O474.js?v=548792af:10
node_modules/parse/node.js	@	node.js:1
__require2	@	chunk-7FP5O474.js?v=548792af:10
(anonymous)	@	node.js:1
await in (anonymous) (async)		
(anonymous)	@	(index):201

Expected Outcome
Parse gets imported correctly.
Environment
Package.json:
{
	"name": "my-app",
	"version": "0.0.1",
	"scripts": {
		"dev": "vite dev",
		"build": "vite build",
		"preview": "vite preview",
		"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
		"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
	},
	"devDependencies": {
		"@fontsource/fira-mono": "^4.5.10",
		"@neoconfetti/svelte": "^1.0.0",
		"@sveltejs/adapter-auto": "^2.0.0",
		"@sveltejs/kit": "^1.5.0",
		"@types/cookie": "^0.5.1",
		"svelte": "^3.54.0",
		"svelte-check": "^3.0.1",
		"tslib": "^2.4.1",
		"typescript": "^4.9.3",
		"vite": "^4.0.0"
	},
	"type": "module",
	"dependencies": {
		"parse": "^4.0.0-alpha.12"
	}
}

Server

Parse Server version: no server involved, SDK version see above
Operating system: linux
Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

System (MongoDB or Postgres): none
Database version: none
Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): none

Client

Parse JS SDK version: 4.0.0-alpha.12

Logs

Duplicate issue #2181: Parse error in vite ( back4app ) on Parse.initialize: EventEmitter is not a constructor
Created: 2024-06-22T06:30:48Z
New Issue Checklist


 I am not disclosing a vulnerability.
 I am not just asking a question.
 I have searched through existing issues.
 I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK. 

Issue Description

When calling Parse.initialize with the proper arguments in my vite react application, I get this error:  EventEmitter is not a constructor
This is the corresponding code:

Steps to reproduce


Create a vite app ( mine was a react-ts one )
Try to initialize parse SDK in the app
You will get the error below

Actual Outcome


Expected Outcome

No errors
Workaround
Install the events package  pnpm install events
Environment

Server

Operating system: Ubuntu 23.10
Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): Local

Database

System (MongoDB or Postgres): MongoDB
Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): back4app

Client

Parse JS SDK version: 5.1.0

Logs

Closing comment (2024-06-22T06:33:56Z): Duplicate #1766
You need to polyfill the event emitter.
We could replace the node event emitter with a custom isomorphic event emitter.