Git Product home page Git Product logo

Comments (7)

oakleaf avatar oakleaf commented on May 24, 2024 2

It works! I get why this bothered me, in your READMORE, in the section about TS;

import lumigo from '@lumigo/tracer';

const myHandler = async (event, context, callback) => { ... }

exports.handler = lumigo({ token: 'YOUR-TOKEN-HERE' }).trace(myHandler) 

It threw me off, because I also wrote exports.handler = lumigo({ token: 'YOUR-TOKEN-HERE' }).trace(myHandler)

But in your example above, you wrote (the correct way of exporting) export const handler = ... and that was the reason of the error!

Thanks guys!

from lumigo-node.

doriaviram avatar doriaviram commented on May 24, 2024 1

Hey @oakleaf, we checking it out

from lumigo-node.

doriaviram avatar doriaviram commented on May 24, 2024

Hey @oakleaf "type": "module" in the client package.json didnt help us to reproduce the problem, can you share more details about your package?

from lumigo-node.

doriaviram avatar doriaviram commented on May 24, 2024

@oakleaf
We can add let exports = {} that probably will solve the problem, but we want to reproduce the issue first

from lumigo-node.

oakleaf avatar oakleaf commented on May 24, 2024

In my package.js i have "type": "module", so I can use "import" instead of const lumigo = require(...), this together with NodeJS14 in Lambda (AWS).

At the top of my index.js-file (my handler):
import lumigo from "@lumigo/tracer";

This exactly gives me the error;

{ "errorType": "ReferenceError", "errorMessage": "exports is not defined in ES module scope\nThis file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.", "trace": [ "ReferenceError: exports is not defined in ES module scope", "This file is being treated as an ES module because it has a '.js' file extension and '/var/task/package.json' contains \"type\": \"module\". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.", " at file:///var/task/index.js:179:1", " at ModuleJob.run (internal/modules/esm/module_job.js:183:25)", " at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)", " at /var/runtime/deasync.js:23:15", " at _tryAwaitImport (/var/runtime/UserFunction.js:74:12)", " at _tryRequire (/var/runtime/UserFunction.js:162:21)", " at _loadUserApp (/var/runtime/UserFunction.js:197:12)", " at Object.module.exports.load (/var/runtime/UserFunction.js:242:17)", " at Object.<anonymous> (/var/runtime/index.js:43:30)", " at Module._compile (internal/modules/cjs/loader.js:1085:14)" ] }

And as you can see in the error message, it complains about exports not being defined. All my own classes and modules has "exportations" in each document, eg: export default class Image

Maybe you need to enable nodejs14 in your build? https://github.com/lumigo-io/lumigo-node/blob/master/package.json says nothing about nodejs14 in the description (I get it, it's probably not just updated yet)

I also use this module, https://github.com/lovell/sharp which works fine, maybe they have some configurations going for them?

Maybe just build it with a newer nodejs? https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node-js

from lumigo-node.

doriaviram avatar doriaviram commented on May 24, 2024

Sharing working test that we just made
package.json

{
  "name": "example",
  "version": "0.0.1",
  "main": "src/child.js",
  "license": "MIT",
  "type": "module",
  "private": true,
  "dependencies": {
    "@lumigo/tracer": "file:../lumigo-node-d_exmaple.tgz"
  }
}

serverless.yml

service: lumigo-test

provider:
  name: aws
  region: us-west-2
  runtime: nodejs14.x
  environment:
    LUMIGO_DEBUG: true

functions:
  child:
    handler: src/index.handler
    timeout: 60
    memory: 2048

src/index.js

import lumigo from '@lumigo/tracer';

const lumigoLib = lumigo({ token: 't_xxxxxxxxxxxxxxxxxxxx', debug: true });

export const handler = lumigoLib.trace(async (event, context) => {
  console.log('Event', event);
});

We try to understand what is different in your case, do you have an extra configuration that may be relevant?

from lumigo-node.

doriaviram avatar doriaviram commented on May 24, 2024

@oakleaf Thanks, we will update the readme

from lumigo-node.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.