fastify / fastify-secure-session

Create a secure stateless cookie session for Fastify
MIT License
201 stars 45 forks source link

"No native build was found" #190

Closed monteiz closed 1 year ago

monteiz commented 1 year ago

Prerequisites

Fastify version

4.17.0

Plugin version

6.1.0

Node.js version

18.16.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

12.6.5

Description

Cannot execute my server because of this error (it seems related to sodium-native though):

Error: No native build was found for platform=darwin arch=x64 runtime=node abi=108 uv=1 libc=glibc node=18.16.0 webpack=true
    loaded from: /var/opt/src/my_server/dist

    at load.resolve.load.path (/var/opt/src/my_server/dist/server.cjs:217977:9)
    at load (/var/opt/src/my_server/dist/server.cjs:217939:30)
    at ./node_modules/sodium-native/index.js (/var/opt/src/my_server/dist/server.cjs:288036:101)
    at __webpack_require__ (/var/opt/src/my_server/dist/server.cjs:393084:42)
    at ./node_modules/@fastify/secure-session/index.js (/var/opt/src/my_server/dist/server.cjs:4935:16)
    at __webpack_require__ (/var/opt/src/my_server/dist/server.cjs:393084:42)
    at ./src/passport.js (/var/opt/src/my_server/dist/server.cjs:337150:81)
    at __webpack_require__ (/var/opt/src/my_server/dist/server.cjs:393084:42)
    at ./src/api/Logs.js (/var/opt/src/my_server/dist/server.cjs:330342:70)
    at __webpack_require__ (/var/opt/src/my_server/dist/server.cjs:393084:42)

I have tried to transpile and run with node 16.20.0 and 14.21.3, and also with @fastify/secure-session 5.3.0.

If I do not include @fastify/secure-session the app runs fine.

Steps to Reproduce

I have created a repository: https://github.com/monteiz/fastify_secure_session_issue

Expected Behavior

Run without errors.

monteiz commented 1 year ago

If I run the server with babel-node, the execution goes fine:

% NODE_ENV=development nodemon --inspect=50002 --watch src --exec node_modules/.bin/babel-node src/server.js
[nodemon] 2.0.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching dir(s): src/**/*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node_modules/.bin/babel-node --inspect=50002 src/server.js`
Debugger listening on ws://127.0.0.1:50002/f20d9cda-9b56-4d55-8a84-9ede58557e95
For help, see: https://nodejs.org/en/docs/inspector
HTTPS server running on https://localhost:4501 [development]
mcollina commented 1 year ago

This module relies on a native addon. As a result, I don't think it's possible to bundle it safely. Avoid bundling.

monteiz commented 1 year ago

Thank you Matteo. For other people facing the same situation, here is the webpack configuration snippet to use:

externals: {
    "@fastify/secure-session": "commonjs @fastify/secure-session",
}