gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.27k stars 10.31k forks source link

bundle failed trying to import fully specified paths #31077

Closed Josehower closed 3 years ago

Josehower commented 3 years ago

Description

When using fully specified paths in imports e.g export { quiz as jsFunctions } from './js-functions.js';

gatsby send this error message

image

Steps to reproduce

  1. add type: module to package.json
  2. create an import with fully specified paths
  3. try to run the gatsby site

Expected result

Gatsby should allow imports with .js extention

Actual result

Gatsby fail trying to generate JavaScript bundle

Environment

Run gatsby info --clipboard in your project directory and paste the output here.

$ yarn gatsby info --clipboard yarn run v1.22.5 $ D:\upleveled-softwork\courses\node_modules.bin\gatsby info --clipboard

System: OS: Windows 10 10.0.19041 CPU: (4) x64 Intel(R) Core(TM) i5-7400 CPU @ 3.00GHz Binaries: Node: 16.0.0 - ~\AppData\Local\Temp\yarn--1619542324765-0.4257021548777624\node.CMD Yarn: 1.22.5 - ~\AppData\Local\Temp\yarn--1619542324765-0.4257021548777624\yarn.CMD npm: 7.10.0 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 90.0.4430.93 Edge: Spartan (44.19041.906.0), Chromium (90.0.818.46)

✨ Done in 4.44s.

wardpeet commented 3 years ago

Hi @Josehower!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

We have tried the example above and we couldn't see the above error.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

karlhorky commented 3 years ago

@wardpeet in trying to help José a bit just now, I thought it was maybe related to your PR over here: https://github.com/gatsbyjs/gatsby/pull/29576#issuecomment-827504491

karlhorky commented 3 years ago

I guess there may still be an issue with TypeScript (user-created .tsx and .ts files that use imports with .js file extensions) though, which may be the missing detail here.

wardpeet commented 3 years ago

🤔 maybe. Packages should not export ts or tsx files. I would love some kind of reproduction :)

karlhorky commented 3 years ago

Yep, José is working on one now, should be here soon :)

Josehower commented 3 years ago

https://codesandbox.io/s/serene-leaf-2vivd?file=/src/components/layout.tsx

here you have the link for an Out of the box gatsby sandbox with minimal changes the changes done:

image

image

Note: make sure you go to the browser port: 8000 tab

karlhorky commented 3 years ago

To be clear what we're trying to do:

  1. We are using ESM via "type": "module" in package.json
  2. We are using fully-specified import paths (with .js extension)
  3. We are using TypeScript via babel-loader (via babel-preset-gatsby)

With regular TypeScript, this works, and is recommended: https://github.com/microsoft/TypeScript/issues/41887#issuecomment-741968855

This is the intended behavior; because TypeScript doesn't modify JavaScript code you write, the import path you write should be the one you want to appear in the output .js file

With Gatsby TypeScript, it doesn't work.

Edit: Upon further reflection, this seems like a bug in webpack's module resolution algorithm (or in babel-loader and ts-loader)

@Josehower will create issues over there.

Edit 2: Issue for webpack open: https://github.com/webpack/webpack/issues/13252

github-actions[bot] commented 3 years ago

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

github-actions[bot] commented 3 years ago

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜