dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.92k stars 1.13k forks source link

reflect-metadata eror #1502

Open Yasin-Dev81 opened 3 years ago

Yasin-Dev81 commented 3 years ago

General Question

Read the Notes and fill out the form. Switch to Preview for reading.

Notes

Your issue will be closed if you violate any rule below.

Form

Put an [x] if you meet the condition, else leave [ ].

Question

A specific question, so it's understandable to anyone. You may add pictures.

YOUR QUESTION HERE I want to post a video on Instagram, but even though I installed reflect-metadata, I still get this error

Code

/* tslint:disable:no-console */
const { IgApiClient } = require('./index.ts');
const { sample } = require('lodash');

const ig = new IgApiClient();
// You must generate device id's before login.
// Id's generated based on seed
// So if you pass the same value as first argument - the same id's are generated every time
ig.state.generateDevice(process.env.IG_USERNAME);
// Optionally you can setup proxy url
ig.state.proxyUrl = process.env.IG_PROXY;
(async () => {
  // Execute all requests prior to authorization in the real Android application
  // Not required but recommended
  await ig.simulate.preLoginFlow();
  const loggedInUser = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
  // The same as preLoginFlow()
  // Optionally wrap it to process.nextTick so we dont need to wait ending of this bunch of requests
  process.nextTick(async () => await ig.simulate.postLoginFlow());
  // Create UserFeed instance to get loggedInUser's posts
  const userFeed = ig.feed.user(loggedInUser.pk);
  const myPostsFirstPage = await userFeed.items();
  // All the feeds are auto-paginated, so you just need to call .items() sequentially to get next page
  const myPostsSecondPage = await userFeed.items();
  await ig.media.like({
    // Like our first post from first page or first post from second page randomly
    mediaId: sample([myPostsFirstPage[0].id, myPostsSecondPage[0].id]),
    moduleInfo: {
      module_name: 'profile',
      user_id: loggedInUser.pk,
      username: loggedInUser.username,
    },
    d: sample([0, 1]),
  });
})();

Error and Output

import 'reflect-metadata';
^^^^^^

SyntaxError: Cannot use import statement outside a module
←[90m    at Object.compileFunction (node:vm:352:18)←[39m
←[90m    at wrapSafe (node:internal/modules/cjs/loader:1031:15)←[39m
←[90m    at Module._compile (node:internal/modules/cjs/loader:1065:27)←[39m
←[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m    at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m
←[90m    at require (node:internal/modules/cjs/helpers:94:18)←[39m
    at Object.<anonymous> (D:\code\instagram-private-api-master\src\tt.ts:2:25)
←[90m    at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m
Nerixyz commented 3 years ago

You're trying to run typescript code. You can't do that.

Yasin-Dev81 commented 3 years ago

So please tell me how to execute this code .