-
Notifications
You must be signed in to change notification settings - Fork 12
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
Building problem with typescript #31
Comments
Raw filesystem access is the only reason there is a different build for node vs browser at this point - the noderawfs flag is passed to the emscripten compiler at build time for node, but not for the browser (including it seems to break the browser build). I think it depends on how h5wasm is loaded into the referring package you're using. If you do Can you tell me what package you're trying to build? |
Ok, I figurate different the difference between web and node, and why file systems did not work in the ESM build. I think the problem is that the ht-util.js script from emscripten has ems syntax and not cjs, and this get messy with the import.meta.url and require statements. When I use TSC or ESBUILD it does like the ems version better since then both files are esm modules. Have you a working example of using h5wasm in a node project with typescript? The h5wasm works when I use it with mjs, but if you try to use h5wasm win typescript then both tsc and esbuilds fails. I've mange to get this to work with using esbuild and then a search and replace into the compiled code. Possible solutions?
|
I didn't really want to support the commonjs build anymore, as it adds complexity to the project. I had to do the same thing as you when building the commonjs module: search and replace on the output. I am able to build a test typescript project using h5wasm v0.4.6 if I set "type": "module" in the package.json of the test project and use a tsconfig.json like this: {
"compilerOptions": {
"module": "es6",
"esModuleInterop": true,
"target": "es6",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "dist",
"types": ["node"]
},
"lib": ["es2020"],
} Then an index.ts that looks like this compiles and runs just fine in node (slightly modified from the node tests in the h5wasm test folder): import { strict as assert } from 'assert';
import h5wasm from 'h5wasm';
async function bool_test() {
await h5wasm.ready;
var f = new h5wasm.File('./array.h5', 'r');
const bool_data = f.get('bool');
assert(bool_data instanceof h5wasm.Dataset);
console.log('value:', bool_data.value);
// should be: [ false, true, true, false ]
console.log('metadata: ', bool_data.metadata);
}
export const tests = [
{
description: 'Read boolean datasets',
test: bool_test,
},
];
export default tests;
bool_test(); (note that you have to npm install node-ts if you want to use the assert as above) |
I realize you've written this package for maximum portability (browser, node), however, if I try to build a simple test file (like yours above) with both module and moduleResolution set to "nodenext", I receive a typescript error indicating that relative import paths need explicit file extensions. node_modules/h5wasm/src/hdf5_hl.d.ts:1:113 - error TS2834: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Consider adding an extension to the import path. 1 import type { Status, Metadata, H5Module, CompoundMember, CompoundTypeMetadata, EnumTypeMetadata, Filter } from "./hdf5_util_helpers"; Unfortunately, I appear to be stuck as other modules that I need require nodenext. Would you consider modifying this package to be compatible with nodenext? |
I would be happy to make that modification, but I lack expertise in the subtleties of packaging. I would welcome a PR from someone with more experience! |
Brian:
It works with both module and moduleResolution set to nodenext. While poking around, it seems hdf5_utils.d.ts will likely need the same change.
Thanks for pursuing this so promptly. I look forward to the patched version.
Adam
…________________________________
From: Brian Benjamin Maranville ***@***.***>
Sent: Wednesday, April 3, 2024 9:39 AM
To: usnistgov/h5wasm ***@***.***>
Cc: Adam Greenberg ***@***.***>; Mention ***@***.***>
Subject: Re: [usnistgov/h5wasm] Building problem with typescript (Issue #31)
@mousseq<https://github.com/mousseq> - can you try out the fix suggested by @axelboc<https://github.com/axelboc> in #71<#71> ?
If it works for you, I'll merge it in and make a new patch release.
—
Reply to this email directly, view it on GitHub<#31 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AX65Z52RCGFCN4IU45NTQNDY3QBBJAVCNFSM56LDLDLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBTGQ3DIMRZGM2A>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@mousseq : Patched version published just now... v0.7.4 |
Brian:
Many thanks for the quick turnaround:
Adam
…________________________________
From: Brian Benjamin Maranville ***@***.***>
Sent: Wednesday, April 3, 2024 11:05 AM
To: usnistgov/h5wasm ***@***.***>
Cc: Adam Greenberg ***@***.***>; Mention ***@***.***>
Subject: Re: [usnistgov/h5wasm] Building problem with typescript (Issue #31)
@mousseq<https://github.com/mousseq> : Patched version published just now... v0.7.4
—
Reply to this email directly, view it on GitHub<#31 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AX65Z5ZXTBLXFK25TAMF5F3Y3QLB5AVCNFSM56LDLDLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBTGQ4DOMJQHA3Q>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I'm having problem with building a typescript project that referees this package. The problem seems to be that the Node version of the code is using a require of an ESM module which neither TSC or ESBUILD like.
I can get the project to build if I force to use the ESM module of the project, but then I does not get access to the file system. Is the WASM code for the ESM build enabled with file access?
The text was updated successfully, but these errors were encountered: