Node js trouble with require and import
Hey folks, I am getting node js error that I was hoping someone could help me with.
This is a simple example, that works...
const Max = require('max-api');
Max.post("\n=== Test Complete ===");But as soon as I import another js file, node does not like the require directive. I get the error listed below,
import { Sequencer } from './sequencer.js';
const Max = require('max-api');
const seq = new Sequencer();
Max.post("\n=== Test Complete ===");
Can someone please help me sort this issue out.
Rather than mixing CJS (require) and ESM (import) syntax, have you tried sticking to one, e.g using import only?
import { Sequencer } from './sequencer.js';
import Max from "max-api";
Or, stick to using require only, and your project will stay as CJS.
P.S: If you're interested in sticking to a pure ESM project, and would like to potentially use Typescript to keep things neat and tidy, this is an incredible project made specifically for Max that allows you to do so: https://github.com/liminalfield/max-ts-dev-framework
import { Sequencer } from './sequencer.js';
import Max from "max-api";
Ahhh yes that fixed it! Thanks!
You're welcome, glad it's working!