-
Notifications
You must be signed in to change notification settings - Fork 333
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
Error resolving GOV.UK Frontend subpath exports in Node.js 17+ #3755
Labels
🐛 bug
Something isn't working the way it should (including incorrect wording in documentation)
javascript
Comments
romaricpascal
added
🐛 bug
Something isn't working the way it should (including incorrect wording in documentation)
javascript
labels
Jun 6, 2023
github-project-automation
bot
moved this to Backlog 🗄
in GOV.UK Design System cycle board
Jun 6, 2023
Thanks @romaricpascal The hybrid idea was because package.json subpath patterns requires Node.js 12.20.0+ But we should check if a single "exports": {
".": {
"sass": "./govuk/all.scss",
"import": "./govuk-esm/all.mjs",
"require": "./govuk/all.js"
},
"./govuk/": "./govuk/",
"./govuk-esm/": "./govuk-esm/",
"./package.json": "./package.json",
"./*": "./*"
}, |
This was referenced Jun 6, 2023
colinrotherham
added a commit
that referenced
this issue
Jun 15, 2023
We switched to “subpath patterns” recently (Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
added a commit
that referenced
this issue
Jun 15, 2023
We switched to “subpath patterns” recently (Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
added a commit
that referenced
this issue
Jun 15, 2023
We switched to “subpath patterns” recently (Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
added a commit
that referenced
this issue
Jun 16, 2023
We switched to “subpath patterns” recently (Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
@romaricpascal Updated the description to show how both v4 and v5 are affected |
colinrotherham
changed the title
Error resolving GOV.UK Frontend subpath exports in Node.js 17+
Jun 16, 2023
require
ing or import
ing specific JavaScript files in Node >=17
colinrotherham
added a commit
that referenced
this issue
Jun 16, 2023
We switched to “subpath patterns” recently (supported in Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
moved this from Backlog 🗄
to In progress 📝
in GOV.UK Design System cycle board
Jun 16, 2023
colinrotherham
moved this from In progress 📝
to Needs review 🔍
in GOV.UK Design System cycle board
Jun 16, 2023
colinrotherham
added a commit
that referenced
this issue
Jun 16, 2023
We hadn’t realised that support for “subpath exports” with trailing slashes (not asterisks) was deprecated in Node.js 16 and removed in Node.js 17 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- But fully switching to “subpath patterns” requires Node.js 12.20+ so both flavours will be needed for backwards compatibility Fixes: #3755
Node.js <= 12.18 fix (v5 only) ready for review: Node.js >= 17 fix (v4 only) ready for review: |
colinrotherham
added a commit
that referenced
this issue
Jun 19, 2023
We switched to “subpath patterns” recently (supported in Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
added a commit
that referenced
this issue
Jun 19, 2023
We switched to “subpath patterns” recently (supported in Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
querkmachine
pushed a commit
that referenced
this issue
Jun 23, 2023
We switched to “subpath patterns” recently (supported in Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
moved this from Needs review 🔍
to Done 🏁
in GOV.UK Design System cycle board
Jun 26, 2023
owenatgov
pushed a commit
that referenced
this issue
Jul 3, 2023
We hadn’t realised that support for “subpath exports” with trailing slashes (not asterisks) was deprecated in Node.js 16 and removed in Node.js 17 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- But fully switching to “subpath patterns” requires Node.js 12.20+ so both flavours will be needed for backwards compatibility Fixes: #3755
colinrotherham
added a commit
that referenced
this issue
Jul 19, 2023
We switched to “subpath patterns” recently (supported in Node.js 12.20+) but hadn’t realised that “subpath exports” with trailing slashes (not asterisks) were still needed for older versions We need both flavours because trailing slashes in exports were deprecated in Node.js 16 https://nodejs.org/docs/latest-v18.x/api/deprecations.html#dep0148-folder-mappings-in-exports-trailing- Fixes: #3755
colinrotherham
added a commit
to alphagov/govuk-prototype-kit
that referenced
this issue
Aug 24, 2023
Brings in this bug fix: alphagov/govuk-frontend#3755
colinrotherham
added a commit
to alphagov/govuk-prototype-kit
that referenced
this issue
Aug 24, 2023
Brings in this bug fix: alphagov/govuk-frontend#3755
colinrotherham
added a commit
to alphagov/govuk-prototype-kit
that referenced
this issue
Aug 24, 2023
Brings in this bug fix: alphagov/govuk-frontend#3755
colinrotherham
added a commit
to alphagov/govuk-prototype-kit
that referenced
this issue
Aug 24, 2023
Brings in this bug fix: alphagov/govuk-frontend#3755
colinrotherham
added a commit
to alphagov/govuk-prototype-kit
that referenced
this issue
Aug 31, 2023
Brings in this bug fix: alphagov/govuk-frontend#3755
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
🐛 bug
Something isn't working the way it should (including incorrect wording in documentation)
javascript
Description of the issue
We've identified two scenarios when trying to
require()
orimport
GOV.UK Frontend"exports"
"exports"
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './govuk/all.js' is not defined by "exports" in /Users/romaric.pascal/code/package-exports/node_modules/govuk-frontend/package.json
This can happen if extending our components and having a test suite run with a tool like Mocha that uses native Node
require
orimport
to load modules.Steps to reproduce the issue
Create a new prototype GOV.UK Frontend v4.6.0
npx govuk-prototype-kit create package-exports cd package-exports
Run Node.js
require.resolve()
to locate GOV.UK Frontend's default exportsRun Node.js
require.resolve()
to locate a subpath exportnode --eval "console.log(require.resolve('govuk-frontend/govuk/all.js'))"
Using Node.js 16 you'll see the following warning:
Using Node.js 17+ you'll see the following error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './govuk/all.js' is not defined by "exports" in /node_modules/govuk-frontend/package.json
Actual vs expected behaviour
Instead of receiving an error, the subpath export should should be resolved properly.
@colinrotherham suggested the following update to our exports to achieve so, using both :
The text was updated successfully, but these errors were encountered: