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

ERR_UNSUPPORTED_DIR_IMPORT #7898

Closed
ziimakc opened this issue Aug 30, 2023 · 2 comments · Fixed by #7901 or #7945
Closed

ERR_UNSUPPORTED_DIR_IMPORT #7898

ziimakc opened this issue Aug 30, 2023 · 2 comments · Fixed by #7901 or #7945
Assignees
Labels
Milestone

Comments

@ziimakc
Copy link

ziimakc commented Aug 30, 2023

Describe the bug

SWC version 1.79+ omits /index.js in imports when compiled, which results in runtime error for this imports:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'redacted/modules/ping/gql' is not supported resolving ES modules imported from 'redacted'

Probably this MR is the cause.
Directory imports are not allowed:

Mandatory file extensions
A file extension must be provided when using the import keyword to resolve relative or absolute specifiers. Directory indexes >(e.g. './startup/index.js') must also be fully specified.
This behavior matches how import behaves in browser environments, assuming a typically configured server.

Input code

typescript:

import { pingIndex } from "../modules/ping/gql/index.js";

compiled (swc 1.79):

import { pingIndex } from "../modules/ping/gql"; # this is not correct

compiled (swc 1.78):

import { pingIndex } from "../modules/ping/gql/index.js"; # works as expected


### Config

```json
{
	"$schema": "https://json.schemastore.org/swcrc",
	"module": {
		"type": "es6",
		"strictMode": true,
		"noInterop": false
	},
	"jsc": {
		"parser": {
			"syntax": "typescript",
			"dynamicImport": true
		},
		"transform": { "legacyDecorator": true, "decoratorMetadata": false },
		"target": "es2022",
		"externalHelpers": true,
		"keepClassNames": true,
		"paths": {
			"@app/*": ["./src/*"]
		},
		"baseUrl": "."
	},
	"sourceMaps": true
}

Playground link

Can't reproduce in playground.

Reprodution repo

SWC Info output

Some resent npx issue doesn't allow to run this, error:

Cannot read properties of undefined (reading 'isStream')

Expected behavior

Compiled code should include index.js as it was defined.

import { pingIndex } from "../modules/ping/gql/index.js";

Actual behavior

Compiled code omits index.js.

import { pingIndex } from "../modules/ping/gql";

Version

1.79+

Additional context

No response

@ziimakc ziimakc added the C-bug label Aug 30, 2023
@kdy1 kdy1 self-assigned this Aug 31, 2023
@kdy1 kdy1 added this to the Planned milestone Aug 31, 2023
kdy1 added a commit that referenced this issue Aug 31, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.82 Sep 1, 2023
@kdy1
Copy link
Member

kdy1 commented Sep 1, 2023

Reopening as fix was reverted. #7906

@kdy1 kdy1 reopened this Sep 1, 2023
@kdy1 kdy1 modified the milestones: v1.3.82, Planned Sep 1, 2023
kdy1 added a commit that referenced this issue Sep 14, 2023
…js` (#7945)

**Description:**

 - `jsc.module.resolveFully` is added to support resolving as `.js`.

**Related issue:**

 - Closes #7861
 - Closes #7898
@kdy1 kdy1 modified the milestones: Planned, v1.3.85 Sep 15, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 15, 2023

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.