dachev / node-cld

Language detection for Javascript (Node). Based on the CLD2 (Compact Language Detector) library from Google.
Apache License 2.0
315 stars 55 forks source link

Building a Node project using Esbuild and Typescript. #76

Open seivan opened 1 year ago

seivan commented 1 year ago

Might be related to https://github.com/dachev/node-cld/issues/67 But I am having some issues using cld in a Node project using esbuild and Typescript.

$ yarn run make                                                                                  
✘ [ERROR] Could not resolve "./build/Release/cld"

    .yarn/unplugged/cld-npm-2.9.0-8b7667576b/node_modules/cld/index.js:2:21:
      2 │ const cld2 = require('./build/Release/cld');

Not sure if the path is being used relative to my cwd (since that's wrong) or if something is missing in the <modules_folder>/build/Release folder?

$ ls                                                                                     
cld-c.a    cld.node   obj.target

These are the files there. It only happens when compiling using esbuild. Doesn't happen with ts-node for instance.

This is how I run it

esbuild src/main.ts --bundle --sourcemap --platform=node --target=ES2022 --outfile=build/dist/main.js

This is how I import it

import { detect } from "cld"
dachev commented 1 year ago

@seivan what directory did you ls in your last message? Was it ./node_modules/cld/build/Release?

GA1 commented 11 months ago

Hey @dachev, any update on this? I'm having the same issue:

When using the library in typescript with: import cld from 'cld'

I get:

in my IDE:

Screenshot 2023-11-27 at 11 43 16

in my terminal when running the project:

 Error: Cannot find module './build/Release/cld'
 Require stack:
   - ***********************************************/node_modules/cld/index.js
       at Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
     at Module._load (node:internal/modules/cjs/loader:841:27)
     at Module.require (node:internal/modules/cjs/loader:1061:19)
     at require (node:internal/modules/cjs/helpers:103:18)
     at Object.<anonymous> (********************************************************/node_modules/cld/index.js:2:14)
       at Module._compile (node:internal/modules/cjs/loader:1159:14)
       at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
       at Module.load (node:internal/modules/cjs/loader:1037:32)
       at Module._load (node:internal/modules/cjs/loader:878:12)
       at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29) {
       code: 'MODULE_NOT_FOUND',
     requireStack: [
         '***********************************************/node_modules/cld/index.js'
       ]
     }