kwonoj / cld3-asm

WebAssembly based Javascript bindings for google Compact Language Detector v3
MIT License
56 stars 7 forks source link

Issue with Vite: TypeError: runtimeModule is not a function #142

Closed jenswilms closed 2 months ago

jenswilms commented 2 months ago

I run across this issue:

Error in getLanguage: TypeError: runtimeModule is not a function
    at cld3-asm.js?v=13ef29a7:1958:23
    at Module.loadModule (cld3-asm.js?v=13ef29a7:2138:10)

I've been using it in a React app with Vite.

I've been trying to figure out what exactly it was, but ultimately found out that you have to specify the path in which the module gets loaded.

Solution

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      'cld3-asm': 'cld3-asm/dist/cjs/index.js'
    }
  }
})
kwonoj commented 2 months ago

I'm not sure this is specific issue for the pkg itself, since cld3-asm's export is defined pretty standard way: https://github.com/kwonoj/cld3-asm/blob/master/package.json#L5

Sounds like more close to vite's behavior though I can't say 100% for sure.