0

trying to run https://github.com/airgram/airgram

From this post, (node:9374) Warning: To load an ES module, set "type": "module"

already add

{"type": "module"}

To package.json

Here is my code:

root@faka:~/airgram# cat face.js 
import { Airgram, Auth, prompt, toObject } from 'airgram'

const airgram = new Airgram({
  apiId: process.env.APP_ID,
  apiHash: process.env.APP_HASH
})


airgram.use(new Auth({
  code: () => prompt(`Please enter the secret code:\n`),
  phoneNumber: () => prompt(`Please enter your phone number:\n`)
}))

void (async () => {
  const me = toObject(await airgram.api.getMe())
  console.log(`[me]`, me)
})

// Getting all updates
airgram.use((ctx, next) => {
  if ('update' in ctx) {
    console.log(`[all updates][${ctx._}]`, JSON.stringify(ctx.update))
  }
  return next()
})

// Getting new messages
airgram.on('updateNewMessage', async ({ update }, next) => {
  const { message } = update
  console.log('[new message]', message)
  return next()
})

But still got error:

root@faka:~/airgram# node face.js 
internal/process/esm_loader.js:74
    internalBinding('errors').triggerUncaughtException(
                              ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'airgram' imported from /root/airgram/face.js
    at packageResolve (internal/modules/esm/resolve.js:664:9)
    at moduleResolve (internal/modules/esm/resolve.js:705:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:798:11)
    at Loader.resolve (internal/modules/esm/loader.js:100:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:246:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:47:40)
    at link (internal/modules/esm/module_job.js:46:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}
2
  • This runtime issue is not caused by typescript. And typescript is a superset of javascript. Commented Dec 4, 2022 at 17:31
  • How did you install the package? It's not being found and node is looking in a weird place. It should have just been npm install airgram. Commented Dec 4, 2022 at 17:33

1 Answer 1

1

Your code have many errors when running it first make sure you are install airgram package:

npm install airgram

Second error

 internalBinding('errors').triggerUncaughtException(

you can view this answer to solve it.

Sign up to request clarification or add additional context in comments.

7 Comments

with your answer, I actually created a javaScript file not typeScript. Does that mean tsc fileName.ts is not necessary ? ( since my file name is fileName.js)
I updated the answer, solve the errors Cannot find package 'airgram' by installing airgram package. After fixing it let's show code have an errors again or not.
import { Airgram, Auth, prompt, toObject } from 'airgram' ^^^^^^ SyntaxError: Cannot use import statement outside a module at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12) at internal/main/run_main_module.js:17:47
To solve this error, view these answers stackoverflow.com/q/58384179/5661396 , What node version that you use.
node -v : v12.22.9. AFTER adding { "type": "module" } to package.json. RUN node face.js internal/modules/cjs/loader.js:258 throw e; ^ SyntaxError: Error parsing /home/ubuntu/airgram/package.json: Unexpected token { in JSON at position 1561 at parse (<anonymous>) at readPackage (internal/modules/cjs/loader.js:245:20) (internal/modules/run_main.js:55:24) at internal/main/run_main_module.js:17:47 { path: '/home/ubuntu/airgram/package.json' }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.