Comments (5)
Hey @Divine1 can you give a bit more context. what was the error you were getting with the import statement.
from docs.surrealdb.com.
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.
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
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.
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.
This issue has been resolved now.
from docs.surrealdb.com.
Related Issues (20)
- Documentation: Example of using backup commmand HOT 4
- Documentation: `AUTHENTICATE` clause on `DEFINE SCOPE`
- Documentation: DEFINE TABLE ... RELATION
- Documentation: POST rpc HOT 2
- Bug: Permanent horizontal scrollbar on the left sidebar menu HOT 3
- Documentation: Page navigation doesn't work HOT 2
- Documentation: String lookup table for semver has wrong pointers HOT 2
- Documentation: base64 encoding and decoding functions
- Documentation: example for BREAK not working HOT 1
- Bug: wrong type in math::mean HOT 3
- Documentation: run rpc method HOT 1
- Documentation: Re-write HOT 2
- Documentation: Live Query v2 requires setup before usage
- Documentation: Relate rpc method
- Documentation: GraphQL HOT 1
- Documentation: Update SurrealQL syntax for v2
- Documentation: Typo in `tokenizer/class` explanation
- Documentation: INSERT RELATION HOT 1
- Documentation: Add array::windows() documentation if merged
- Documentation: vector::project docs are identical to vector::normalize
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docs.surrealdb.com.