Comments (7)
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.
Hey @oakleaf, we checking it out
from lumigo-node.
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.
@oakleaf
We can add let exports = {}
that probably will solve the problem, but we want to reproduce the issue first
from lumigo-node.
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.
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.
@oakleaf Thanks, we will update the readme
from lumigo-node.
Related Issues (18)
- No Host header for APIs that call https.request(URL) HOT 1
- Neo4j Tracer support HOT 3
- Test
- Test issue
- Test Issue
- TEST
- Not handling event['requestContext'] is undefined
- Add PR template HOT 2
- Adding build.yml to run tests in GitHub Actions HOT 1
- Integrate in TypeScript Project HOT 2
- Please Add Support for NodeJS 16 HOT 3
- Execution tags globals list not cleared unless tracing HOT 10
- Tracer should handle traceIdArr greater than 3 and should not be throwing unhandled errors HOT 13
- Require Function Warning During Webpack Build
- EMFILE: too many files open HOT 3
- Security vulnerabilities in axios 0.24.0 HOT 1
- -
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lumigo-node.