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

Loam cannot be run under Node.js #94

Open
kochizufan opened this issue Feb 12, 2022 · 3 comments
Open

Loam cannot be run under Node.js #94

kochizufan opened this issue Feb 12, 2022 · 3 comments

Comments

@kochizufan
Copy link

Hi

I want to use this in node.JS environment on local Windows PC, not on web browser.

Just for test, I wrote such ad-hoc code (without webpack or any packaging) and run:

const loam = require("loam")
loam.initialize()

const main = async () => {

  const file = 'png/Nara-Genpyo.png'
  const dataset = await loam.open(file)
  const width = await dataset.width()
  console.log(width)
}

main()

The result is error follow:

ReferenceError: self is not defined
    at Object.<anonymous> (F:\github\loam\node_modules\loam\lib\loam.js:1:197)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (F:\github\loam\index.js:1:14)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

I changed the code like this, but still same error occurs.

const main = async () => {
  const loam = await import("loam")
  loam.initialize()

  const file = 'png/Nara-Genpyo.png'
  const dataset = await loam.open(file)
  const width = await dataset.width()
  console.log(width)
}

main()

Is this expected result?
Loam don't work in node.js environment or it always must be used with webpack-like packager?

@ddohler
Copy link
Collaborator

ddohler commented Feb 14, 2022

Hi @kochizufan ! Thanks for trying out the library. Node is not a supported environment for Loam because on Node it is possible to use the GDAL package (https://www.npmjs.com/package/gdal) instead, which should provide the same functionality (and more). So because GDAL is available, I haven't spent time to make Loam work in Node, and it probably doesn't work in Node right now.

However, if you're unable to use the GDAL library then I would be happy to investigate improving Node support. Thanks again!

@kochizufan
Copy link
Author

Thank you for explanation.
My intension is use wasm version node library with electron.
Some library cause some difficulties in packaging phase, especially in case of new architecture like Mac's M1.
So I want to use wasm-based library as possible.

@ddohler
Copy link
Collaborator

ddohler commented Feb 18, 2022

Got it, thanks for the explanation! That makes a lot of sense to me. I will look into what can be done about this (but currently have limited time for the project, so I do not know when I will be able to complete this work; it may be a while, unfortunately).

@ddohler ddohler changed the title Problem when used with node.js Loam cannot be run under Node.js Feb 18, 2022
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