We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getFileName()
file://
Hello,
With Node 16 and when "type": "module" is specified in package.json, the function getFileName() returns the file name with file:// prefix.
package.json
Example with the reproducible code below: $ node index.js
$ node index.js
Result: file:///Users/myuser/projects/myproject/mytest/index.js
file:///Users/myuser/projects/myproject/mytest/index.js
Expected result: /Users/myuser/projects/myproject/mytest/index.js
/Users/myuser/projects/myproject/mytest/index.js
Reproducible code: package.json
{ "name": "mytest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "callsites": "^4.0.0" } }
index.js
import callsites from 'callsites'; function unicorn() { console.log(callsites()[0].getFileName()); } unicorn();
The text was updated successfully, but these errors were encountered:
This is caused by Node.js: nodejs/node#39787
Sorry, something went wrong.
Node has merged a fix, but would a .replace(/^file:\/\//, '') be a good workaround for compatibility with earlier Node versions?
.replace(/^file:\/\//, '')
If you are here because of aws-cdk-lib,
aws-cdk-lib
hotpatch node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/function.js function findEntry:
node_modules/aws-cdk-lib/aws-lambda-nodejs/lib/function.js
const definingFile = findDefiningFile(), extname = path.extname(definingFile), tsHandlerFile = definingFile.replace( new RegExp(`${extname}$`), `.${id}.ts` ).replace('file://', ''); // ADD THIS!
No branches or pull requests
Hello,
With Node 16 and when "type": "module" is specified in
package.json
, the functiongetFileName()
returns the file name withfile://
prefix.Example with the reproducible code below:
$ node index.js
Result:
file:///Users/myuser/projects/myproject/mytest/index.js
Expected result:
/Users/myuser/projects/myproject/mytest/index.js
Reproducible code:
package.json
index.js
The text was updated successfully, but these errors were encountered: