zardoy / mc-assets

The most complete solution for Minecraft assets (extracted for all versions)
https://npmjs.com/mc-assets
MIT License
0 stars 1 forks source link

Doesn't work without bundler / transpiler like `tsx` #7

Open ClaytonTDM opened 1 week ago

ClaytonTDM commented 1 week ago

I'm unable to use the module with the example code due to the following error:

export * from './stores';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (node:internal/modules/cjs/loader:1378:20)
    at Module._compile (node:internal/modules/cjs/loader:1428:41)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/home/clay/Desktop/DEV/syncraftTextures/index.js:1:75)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)

Node.js v20.17.0

The first line of my file being: const { AssetsParser, getLoadedModelsStore, getLoadedBlockstatesStore } = require('mc-assets');

zardoy commented 1 week ago

It seems it was always tested with a bundler so I never seed this issue, but there is missing "type": "module" in package.json ( you can add it yourself for now into package.json of this module to see if it works). Anyway, it doesn't change the fact that you try to import ESM code from commonjs (require), which is not supported by vanilla node.js: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

ClaytonTDM commented 1 week ago

It also breaks with ESM.

zardoy commented 1 week ago

Ok, I can't get it working with something like this which is stupid, I don't know how I should configure tsconfig to make it work:

// node file.mjs
import { AssetsParser, getLoadedModelsStore, getLoadedBlockstatesStore } from 'mc-assets'
import blockstatesModels from 'mc-assets/dist/blockStatesModels.json' assert { type: 'json' }

const blockstatesStore = getLoadedBlockstatesStore(blockstatesModels)

console.log(blockstatesStore.get('latest', 'stone'))
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '<...>/node_modules/.pnpm/mc-assets@0.2.12/node_modules/mc-assets/dist/stores' imported from <...>/node_modules/.pnpm/mc-assets@0.2.12/node_modules/mc-assets/dist/index.js