Skip to content
New issue

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

Using webpack with pino for serverside builds #200

Closed
wants to merge 0 commits into from

Conversation

joeyvandijk
Copy link

I understand to make it clear this is only ment not for the browser, but I do not see it being used in other files, so why is this still needed?

With tools like webpack the file is not recognized as a javascript file so it breaks the transpiling when using ES6 code.

Could this be deleted? Then I could use it also with projects that use AWS Lambda, etc.

@mcollina
Copy link
Member

mcollina commented Mar 6, 2017

I'm lost, what is the problem? You cannot use pino with webpack on the browser? In the browser you should be loading https://github.com/pinojs/pino/blob/master/package.json#L6.

pretty.js is linked here https://github.com/pinojs/pino/blob/master/package.json#L8 as a standalone CLI tool, and you can also use it programmatically if you need to.

@joeyvandijk
Copy link
Author

The problem is that webpack (in combination with AWS Lambda) detects pretty.js as a non-js file. I want to ignore it but that is not default behaviour, so I was curious why it needs this line.

Do I understand correctly the proposed change is preventing pretty.js being used as a standalone tool? If so, close this PR, because I need to find another way of preventing webpack to fail recognizing pretty.js as a javascript file and not a command file.

@jsumners
Copy link
Member

jsumners commented Mar 6, 2017

pretty.js is the "binary" that is executed in myapp | pino. Therefore, it is most definitely needed.

@jsumners
Copy link
Member

jsumners commented Mar 6, 2017

I think this is a clear example of the benefits of bin.js, @davidmarkclements ;)

pinojs/pino-sapling#1

@davidmarkclements
Copy link
Member

Will webpack autoignore bin.js? If so let's rename, if not then it's a general webpack problem

@jsumners
Copy link
Member

jsumners commented Mar 6, 2017

He's issue, as I understand it, is that we require pretty.js in pino.js. So he can't pack pino.js since his tool doesn't like pretty.js.

@davidmarkclements
Copy link
Member

ah I see - still you'd think webpack (like browserify) could handle that...

at any rate the issue here is either webpack isn't recognising the browser field of the package.json or it is but for some other reason it's parsing pino.js and giving the error

webpack should not be touching pino.js at all - it should be reading from browser.js which doesn't require pretty.js

From what I can see in webpack docs it looks for the browser field...

Perhaps it can be solved with

"resolve": {
  "alias": {
    "pino$": "pino/browser.js"
  }
}

In the package.json

@joeyvandijk would you mind giving that a shot and updating PR?

@joeyvandijk
Copy link
Author

I will have a look tonight if a rename helps or I can find more information how to make it work with webpack. Thanks for the quick updates and insights.

@joeyvandijk
Copy link
Author

@davidmarkclements I am not using Pino in a browser-environment. I am using it for node.js on AWS Lambda (so node.js). So pretty.js is embedded, but webpack skipping the shebang and interpreting pretty.js as a javascript file.

I will test tonight if I can fix it and post it inside this PR.

@davidmarkclements
Copy link
Member

so.. you're using webpack to build server code?

@davidmarkclements davidmarkclements changed the title Why is /usr/bin/env node still needed? Using webpack with pino for serverside server builds Mar 6, 2017
@davidmarkclements davidmarkclements changed the title Using webpack with pino for serverside server builds Using webpack with pino for serverside builds Mar 6, 2017
@joeyvandijk
Copy link
Author

@davidmarkclements yup, to write ES6 node.js code and transpile it back to node.js v4 for AWS Lambda.

@davidmarkclements
Copy link
Member

@joeyvandijk
Copy link
Author

@davidmarkclements have tried it, but does not work. Have checked it twice. :/

@joeyvandijk
Copy link
Author

joeyvandijk commented Mar 6, 2017

@davidmarkclements the whole problem is that pino.js imports pretty.js and that is why it comes into webpack and fails. But if we move the CLI-version in another file, it still can be used with webpack AND the CLI-setup.

Something like

#! /usr/bin/env node

var pretty = require('./pretty.js')
module.exports = pretty

Gonna have a try and run the tests.

@davidmarkclements
Copy link
Member

davidmarkclements commented Mar 6, 2017

the reason @jsumners gave you thumbsdown there (btw) is because transpiling server side code is quite a risky strategy - you're trusting a lot of layers to rewrite code for you in a trusted environment. I'm sure AWS lambda mitigates some of the security vectors there though...

if you absolute think that's the right approach, the only way I think we can solve this for you is to have a separate bin entry point (bin.js or cmd.js) with a hashbang that requires pretty.js

As long as @mcollina and @jsumners are happy with that solution, I'd be happy to accept if you updated PR accordingly (edit - as you just proposed)

@jsumners
Copy link
Member

jsumners commented Mar 6, 2017

I think it's a ridiculous situation (transpiling needs to stop), but I'm fine with a bin.js or cmd.js.

@davidmarkclements
Copy link
Member

@joeyvandijk - you closed?

@joeyvandijk
Copy link
Author

@davidmarkclements apparently I have mistaken git reset to trigger this branch to delete.

The correct code is now in #201 as described above by you and me.

@TheLarkInn
Copy link

@jsumners It's actually a performance benefit to bundle server code, not only for faster load, but also faster resolution then nodes native and slow sync resolver. The problem here is that webpack doesn't understand the '#' symbol as valid JS from it being a bin. A loader or alias can be used to ignore this, but I wouldn't dismiss the idea of bundling node code as being not worthwhile, because it very much so is!

@mcollina
Copy link
Member

Thanks for checking Pino out @theLarkin!
Do you have any data on those benefits?
It would be fantastic to have webpack strip out the top # line in deps if the goal is to better support Node. There are a lot of modules out there using the same pattern we were using here.

@TheLarkInn
Copy link

It raises a great question. Should we treat it just like any other JS and strip the env?

@mcollina
Copy link
Member

I think so. Unless it's the entry point, in which case the user is trying to pack an executable. In this case you probably want to add that back in at the top of the file, and probably make some adjustment so that require.main is correctly transformed. This will be great feature if someone wants to ship a cli tool: faster installs, faster execution, etc.. This might require more work. I'm happy to open a issue on webpack and test this feature if someone wants to work on it (I'm currently snowed under, and I can't commit to any more OSS work atm).

@TheLarkInn
Copy link

TheLarkInn commented Apr 12, 2018 via email

@github-actions
Copy link

github-actions bot commented Feb 7, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants