-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
output standalone server.js does not work with type: module in package.json #41258
Closed
1 task done
Labels
bug
Issue was opened via the bug report template.
Output (export/standalone)
Related to the the output option in `next.config.js`.
Comments
11 tasks
balazsorban44
added
the
Output (export/standalone)
Related to the the output option in `next.config.js`.
label
Oct 7, 2022
balazsorban44
added a commit
that referenced
this issue
Oct 11, 2022
Fixes #41258 When we detect `type: "module"` in `package.json`: ~1. generate `server.mjs`~ Not necessary when `type: "module"` is set. 2. use `import` instead of `require` 3. replace `__dirname` with [ESM compatible alternative](https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/) In this PR, I also moved some tests (those using `output: "standalone"`) to a new `test/production/standalone-mode` directory for easier discoverability in the future. Run the related test with `pnpm test test/production/standalone-mode/type-module/index.test.ts` ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
Kikobeats
pushed a commit
to Kikobeats/next.js
that referenced
this issue
Oct 24, 2022
Fixes vercel#41258 When we detect `type: "module"` in `package.json`: ~1. generate `server.mjs`~ Not necessary when `type: "module"` is set. 2. use `import` instead of `require` 3. replace `__dirname` with [ESM compatible alternative](https://blog.logrocket.com/alternatives-dirname-node-js-es-modules/) In this PR, I also moved some tests (those using `output: "standalone"`) to a new `test/production/standalone-mode` directory for easier discoverability in the future. Run the related test with `pnpm test test/production/standalone-mode/type-module/index.test.ts` ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
bug
Issue was opened via the bug report template.
Output (export/standalone)
Related to the the output option in `next.config.js`.
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
docker
Describe the Bug
generating a standalone output with
output: "standalone"
option, and serving the output withnode server.js
will fail whenpackage.json
has"type": "module"
set, because__dirname
is only available in common js files.Expected Behavior
successfully run
node server.js
(may just need renaming the fileserver.cjs
)Link to reproduction
https://github.com/stefanprobst/issue-next-standalone
To Reproduce
see error message:
The text was updated successfully, but these errors were encountered: