skywalking
skywalking copied to clipboard
[Bug] Agent.start is not a function when I use esm syntax
Search before asking
- [X] I had searched in the issues and found no similar issues.
Apache SkyWalking Component
NodeJS Server Side Agent (apache/skywalking-nodejs)
What happened
When I use ESM syntax in node, it directly throws out agent.start is not a function ,I just copied the usage from Readme like this
import agent from 'skywalking-backend-js';
agent.start();
But when i use cjs synatax
const { default: agent } = require('skywalking-backend-js');
agent.start()
it will work fine
I can reproduce it in node v16 and node v14,lower versions I have not tried
What you expected to happen
work fine
How to reproduce
npm install skywalking-backend-js
and write follow to test.js
import agent from 'skywalking-backend-js';
agent.start();
node test.js
Anything else
No response
Are you willing to submit PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Do we need some other packaging tool (like rollup) to package the chunks in cjs and esm formats separately, and then differentiate them in package.json, like this
main: 'index.cjs'
module: 'index.mjs'
This allows the runtime environment to determine whether to load index.cjs or index.mjs depending on the syntax used
Do we need some other packaging tool (like
rollup) to package the chunks incjsandesmformats separately, and then differentiate them in package.json, like thismain: 'index.cjs' module: 'index.mjs'This allows the runtime environment to determine whether to load
index.cjsorindex.mjsdepending on the syntax used
This sounds good to me, are you willing to open a pull request? @ruleeeer
Do we need some other packaging tool (like
rollup) to package the chunks incjsandesmformats separately, and then differentiate them in package.json, like thismain: 'index.cjs' module: 'index.mjs'This allows the runtime environment to determine whether to load
index.cjsorindex.mjsdepending on the syntax usedThis sounds good to me, are you willing to open a pull request? @ruleeeer
@kezhenxu94 No problem, I'll try to use rollup packaging
Any update?
Any update?
No update .I've been a little busy lately.
I also faced this issue, so I do this to bypass it first
import agent from 'skywalking-backend-js'
const agentInstance = has('default', agent)
? (agent.default as typeof agent)
: agent
agentInstance.start()
@kezhenxu94 @ruleeeer Would you fix this? It seems no update for months