Giter VIP home page Giter VIP logo

Comments (5)

Ekwuno avatar Ekwuno commented on August 21, 2024

Hey @Divine1 can you give a bit more context. what was the error you were getting with the import statement.

from docs.surrealdb.com.

Divine1 avatar Divine1 commented on August 21, 2024

@Ekwuno

below is the error when i use

import { Surreal } from 'surrealdb.js';
const db = new Surreal();
TypeError: _WebSocket_node_js__WEBPACK_IMPORTED_MODULE_2__.default is not a constructor
    at open (webpack:///node_modules/surrealdb.js/esm/library/SurrealSocket.js:93:20)
    at <anonymous> (webpack:///node_modules/surrealdb.js/esm/strategies/websocket.js:86:27)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1)
    at _next (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:22:1)
    at executor (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:27:1)
    at constructor (webpack:///node_modules/zone.js/fesm2015/zone-node.js:1342:21)
    at <anonymous> (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:19:1)
    at connect (webpack:///node_modules/surrealdb.js/esm/strategies/websocket.js:87:27)
    at <anonymous> (webpack:///appserver/db/index.ts:14:12)

from docs.surrealdb.com.

Nash-x9 avatar Nash-x9 commented on August 21, 2024

Can document show environment info? like node version,etc.

I had the same problem,
node v16.20.0
pnpm 8.6.6

const db = new Surreal();
           ^

TypeError: Surreal is not a constructor
    at Object.<anonymous> (/surreal_db/db_cli/index.js:4:12)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

@Ekwuno

below is the error when i use

import { Surreal } from 'surrealdb.js';
const db = new Surreal();
TypeError: _WebSocket_node_js__WEBPACK_IMPORTED_MODULE_2__.default is not a constructor
    at open (webpack:///node_modules/surrealdb.js/esm/library/SurrealSocket.js:93:20)
    at <anonymous> (webpack:///node_modules/surrealdb.js/esm/strategies/websocket.js:86:27)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:3:1)
    at _next (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:22:1)
    at executor (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:27:1)
    at constructor (webpack:///node_modules/zone.js/fesm2015/zone-node.js:1342:21)
    at <anonymous> (webpack:///node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js:19:1)
    at connect (webpack:///node_modules/surrealdb.js/esm/strategies/websocket.js:87:27)
    at <anonymous> (webpack:///appserver/db/index.ts:14:12)

from docs.surrealdb.com.

Nash-x9 avatar Nash-x9 commented on August 21, 2024

I had resolve this question.
blow is my step to init project:

pnpm init
pnpm install surrealdb.node

#create app.js
touch app.js

app.js

const {Surreal} = require('surrealdb.node');

async function main() {
    try {
        const db = new Surreal();
        // connect to database server
        await db.connect('ws://127.0.0.1:8000');

        await db.signin({
            username: 'root',
            password: 'root'
        })
        await db.version().then(result=> {
            console.log(result)
        })
    } catch (e) {
        console.error('ERROR', e);
    }
}

main()

from docs.surrealdb.com.

Ekwuno avatar Ekwuno commented on August 21, 2024

This issue has been resolved now.

from docs.surrealdb.com.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.