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

Node import issue #4

Closed
westn opened this issue Jul 11, 2021 · 2 comments
Closed

Node import issue #4

westn opened this issue Jul 11, 2021 · 2 comments

Comments

@westn
Copy link

westn commented Jul 11, 2021

There seems to be an error on the Node example (https://www.tangram.xyz/docs/getting_started/predict/node).

Reproduce:

  1. run: npm install @tangramxyz/tangram
  2. create an index.js file with the provided code
  3. test and run with: node index.js
  4. Note the error below

Node-version 16.4.2

node:internal/modules/cjs/loader:1112
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/fnordell/Documents/private/machine_learning/node_modules/@tangramxyz/tangram/dist/node.js
require() of ES modules is not supported.
require() of /Users/fnordell/Documents/private/machine_learning/node_modules/@tangramxyz/tangram/dist/node.js from /Users/fnordell/Documents/private/machine_learning/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename node.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/fnordell/Documents/private/machine_learning/node_modules/@tangramxyz/tangram/package.json.

    at new NodeError (node:internal/errors:363:5)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:13)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:816:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at Object.<anonymous> (/Users/fnordell/Documents/private/machine_learning/index.js:3:17)
    at Module._compile (node:internal/modules/cjs/loader:1095:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
    at Module.load (node:internal/modules/cjs/loader:975:32) {
  code: 'ERR_REQUIRE_ESM'
}
@nitsky
Copy link
Contributor

nitsky commented Jul 11, 2021

@westn thanks for filing this issue!

In version 0.5.1, we did not support commonjs modules but forgot to update the documentation on the website to reflect that. We just published a new version (0.5.3) that now supports commonjs modules in addition to ES modules by using the exports key in package.json. If you update to the latest version of @tangramxyz/tangram (0.5.3) everything should work as shown in the documentation. We also added examples in languages/javascript/examples/node in this repo demonstrating the use of both commonjs and ES modules. The example in the docs has also been updated with a small change on line 9: the .buffer field needs to be used from the result of readFileSync. Please incorporate that into your code. Let us know if you run into more problems.

Thank you!

@niklaszantner

@westn
Copy link
Author

westn commented Jul 11, 2021

Thanks! Now it's working as intended. Closing this issue.

@westn westn closed this as completed Jul 11, 2021
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