MylesBorins / node-osc

Open Sound Control protocol library for Node.js
GNU Lesser General Public License v3.0
435 stars 72 forks source link

Can't get import node-osc #39

Closed mgw-sbex closed 4 years ago

mgw-sbex commented 4 years ago

Hi,

I have been trying to follow the rabbithole to use node-osc. It is under my node_modules after installing: Michaels-Mac-Pro:ws-crowdsounds MGW$ npm install node-osc npm WARN ws-crowdsounds@1.0.0 No repository field.

But then using it as in the Readme: import { Client } from 'node-osc'; ^^^^^^

SyntaxError: Cannot use import statement outside a module

SO I added type module to package.json, then yielding: node server.js internal/modules/cjs/loader.js:1173 throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath); ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/MGW/.../ws-crowdsounds/server.js

Found a suggestion that @std/esm cjs might be needed ... but same error...

package.json { "name": "ws-crowdsounds", "version": "1.0.0", "description": "receive msgs for playing sounds remotely", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "@std/esm": "cjs", "type":"module", "dependencies": { "node-osc": "^5.1.0", "ws": "^7.3.1" } }

Any guidance is appreciated! ~

mgw-sbex commented 4 years ago

After upgrading to node 14... it is better...

MylesBorins commented 4 years ago

If you are using the latest version of node 12 or 14 you can use ESM but must use the .mjs file extension for your module or alternatively include "type": "modules" to your package.json if you want to use .js.

As the trouble you are running into here is related to how ESM works in Node.js core I'm going to go ahead and close this, but feel free to ask more questions.