Reputation: 21
I am currently working on a CNC project, I want to be able to parse DXF files into objects in JS. I started with SVGs instead but the drawings did not export as shapes but as lines (a square as four lines and not a shape with four points). So I began to search for a JS library that would help me work with DXF files, I found "dxf-parser" and "three-dxf". I wasn't able to run an example with neither... That might be because I have a very limited experience with vanilla JS , I usually use P5.
So, in conclusion, I am searching for a working example projects of any of these libraries.
What I did by now was to write in the command line:
npm init -y
npm i dxf parser
Then I opened an html file:
<!DOCTYPE html>
<html lang="en">
<head>
</script>
<meta charset="utf-8" />
</head>
<body>
<main>
</main>
<script type="module" src="index.js"></script>
</body>
</html>
And a JS file:
// Grab fileText in node.js or browser
import parse from 'dxf-parser';
const fileText = "./dxfTests/test.dxf";
try {
const dxf = parse(fileText);
}catch(err) {
console.log(err.stack);
}
Then I start click the go live button in VScode and i get this error:
127.0.0.1/:1 Uncaught TypeError: Failed to resolve module specifier "dxf-parser". Relative references must start with either "/", "./", or "../".
Help would be very much appreciated!
Upvotes: 0
Views: 1341
Reputation: 1
Try to change import parse from 'dxf-parser';
to import parse from './dxf-parser.js';
Upvotes: 0