Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Cannot use import statement outside a module #169

Open
ayel01 opened this issue May 11, 2023 · 1 comment
Open

SyntaxError: Cannot use import statement outside a module #169

ayel01 opened this issue May 11, 2023 · 1 comment

Comments

@ayel01
Copy link

ayel01 commented May 11, 2023

Hey everyone,

I have some Problems when trying to import web-ifc-three in my nodeJs Project.
I'm trying to load an ifcModel in my REST Service.
It's just a simple example, but everytime I try to start my backend it throws the following error:

import * as WebIFC from 'web-ifc';
^^^^^^
SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1176:20)
at Module._compile (node:internal/modules/cjs/loader:1218:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at ModuleWrap. (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.15.0

My example-code:

import express from "express";
import IFCLoader from "web-ifc-three";

const app = express();

app.get("/process-ifc", async (req, res) => {
const ifcLoader = new IFCLoader.IFCLoader();
ifcLoader.ifcManager
ifcLoader.load('../rst_basic_sample_project.ifc', (ifcModel) => {
console.log('Model loaded');
});
});

app.listen(3000, () => {
console.log("Server listening at http://localhost:3000");
});

package.json:

{
"name": "ifc-convert",
"version": "0.0.1",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "git",
"url": "..."
},
"author": "...",
"license": "ISC",
"bugs": {
"url": "..."
},
"homepage": "...",
"dependencies": {
"express": "^4.18.2",
"web-ifc-three": "^0.0.125"
}
}

@Curiosit
Copy link

Curiosit commented Aug 24, 2023

Would be good to see the whole project (a github link?), but you might try to edit package.json file and add "type": "module"
..." main": "app.js", "type": "module", "scripts": { ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants