greggman / uzip-module

An ES6 module version of UZIP.js
MIT License
8 stars 1 forks source link

Cannot be used in nodejs #2

Open etclub opened 3 years ago

etclub commented 3 years ago

I hope it can be used in nodejs. Now it reports error:

Uncaught Error: Cannot find module 'uzip-module'
Require stack:
- <repl>
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Module.require (node:internal/modules/cjs/loader:997:19)
    at require (node:internal/modules/cjs/helpers:92:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '<repl>' ]
}
greggman commented 3 years ago

try it now

etclub commented 3 years ago

It works now.

etclub commented 3 years ago

I found something weird. I have a project, say "A", which uses uzip-module. I have another project "B", which imports some file from A. On my macOS, I run node ./B/src/main.js, everything works. While on linux, it reports error:

Please verify that the package.json has a valid "main" entry
{
  code: 'MODULE_NOT_FOUND',
  path: '/home/etclub/A/node_modules/uzip-module/package.json',
  requestPath: 'uzip-module'
}
etclub commented 3 years ago

I am using esm to support import/export. In "B/main.js" I have

import {encode,decode} from '../A'
console.log(decode(encode('test')))

And in "A/index.js" I have

import { deflate, inflate } from 'uzip-module'
export function encode(text){
  return deflate(text)
}
export function decode(buffer){
  return inflate(buffer)
}

I run it by node -r esm main.js