Skip to content

Type error: 'from' expected - 2.35.8 #399

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

Closed
bundyfx opened this issue Jan 19, 2025 · 9 comments · Fixed by #400
Closed

Type error: 'from' expected - 2.35.8 #399

bundyfx opened this issue Jan 19, 2025 · 9 comments · Fixed by #400
Labels
bug Something isn't working released

Comments

@bundyfx
Copy link

bundyfx commented Jan 19, 2025

three@0.171.0
three-stdlib@2.35.8
@react-spring/three@9.7.5
@react-three/drei@9.121.2
@react-three/fiber@9.0.0-rc.4

Problem description:

Building (npm run build) causes the below issue now (as a few hours ago -> 2.35.8)

./node_modules/three-stdlib/index.d.ts:1:10
Type error: 'from' expected.

1 | export * type from './misc/MD2CharacterComplex.d.ts';
| ^
2 | export * type from './misc/ConvexObjectBreaker.d.ts';
3 | export * type from './misc/MorphBlendMesh.d.ts';
4 | export * type from './misc/GPUComputationRenderer.d.ts';
Static worker exited with code: 1 and signal: null
Error: Command "npm run build" exited with 1

Suggested solution:

I had to patch this back to -> export type * from './misc/xxxx.d.ts';
as "export * type from './misc/xxxx.d.ts';" is not valud exporting format.

@bundyfx bundyfx added the bug Something isn't working label Jan 19, 2025
@bundyfx
Copy link
Author

bundyfx commented Jan 19, 2025

Yes, just open the index at -> node_modules/three-stdlib/index.d.ts and fix all the pathing back to normal import format aka (export type * from './environments/RoomEnvironment.d.ts') - then you will need to create a patch with patch-package (npm install patch-package --save-dev) then update your scripts in package json with a postinstall to patch the version when you deploy.

@giantjustin
Copy link

I ran into this as well. It appears to be related to https://github.com/pmndrs/three-stdlib/releases/tag/v2.35.8, and more specifically, the introduction of this patch file: 8e15117#diff-93d353a7a92f421b8eb2cdb883d8c75f31a4ba25d28503ada3a7e5a4e2b5dc0f

Apologies for blasting a block of code below, but I wrote a quick test script to do a sanity-check on the regexes in the above changes. Perhaps it will aid in further validation. (Side note: I highly advise you read the code before blindly running it; there's no reason to trust some random dude's script, and I'm a random dude.)

I excluded shelljs and created a basic sed stand-in for testing purposes. Running this script will create a test file containing some valid module code, then it will perform the new patch operations and write/log the results.

The test output should demonstrate that the above change is now creating invalid syntax.

const fs = require("node:fs");

// Test file
const testFile = "./test.ts";

// Write a minimal test containing valid module code
fs.writeFileSync(
  testFile,
  `
export * from './module';
export { something } from './module.js';
import { AnotherThing } from './another-module';
declare module './module';
`,
);

// Mimic shelljs `sed` so we have a self-contained test script
function sed(searchRegex, replaceValue, file) {
  const content = fs.readFileSync(file, "utf-8");
  const updatedContent = content.replace(searchRegex, replaceValue);
  fs.writeFileSync(file, updatedContent, "utf-8");
}

// Start regex validation from release https://github.com/pmndrs/three-stdlib/releases/tag/v2.35.8

// Add type qualifiers in annotations
sed(/(import|export [*{])\s+(?!type\b)/, "$1 type ", testFile);
// NOTE: if you'd like to test a *potential* fix, comment out the line above and uncomment the line below
// sed(/(import|export {)\s+(?!type\b)/, "$1 type ", testFile);

// Remove .js extensions
sed(/from '(\.[^.]+)\.js'/, "from '$1'", testFile);

// Add explicit .d.ts extensions for ESM
sed(/ from '(\.[^']+)'/, " from '$1.d.ts'", testFile);
sed(/^declare module '(\.[^']+)'/, "declare module '$1.d.ts'", testFile);

// End regex validation

// Log the result
const result = fs.readFileSync(testFile, "utf-8");
console.log("Transformed test.ts:\n", result);

I'm not up to speed on the broader context and objectives around the change that introduced this issue, otherwise I'd open a PR. I know a lot of people rely on the stability of this library, and I don't want to increase the blast radius by making a naive change. Hopefully this is helpful. I appreciate all the hard work that goes into this library.

In the immediate term, I chose to roll back my package-lock.json to a version that resolved to the previous release, but I know that won't work for everyone.

@motiontx
Copy link

The same happens to me but in @react-three/drei/node_modules/three-stdlib/index.d.ts

I used patch-package as a temporary workaround.

@legcy143
Copy link

legcy143 commented Jan 19, 2025

three@0.171.0 three-stdlib@2.35.8 @react-spring/three@9.7.5 @react-three/drei@9.121.2 @react-three/fiber@9.0.0-rc.4

Problem description:

Building (npm run build) causes the below issue now (as a few hours ago -> 2.35.8)

./node_modules/three-stdlib/index.d.ts:1:10 Type error: 'from' expected.

1 | export * type from './misc/MD2CharacterComplex.d.ts';
| ^
2 | export * type from './misc/ConvexObjectBreaker.d.ts';
3 | export * type from './misc/MorphBlendMesh.d.ts';
4 | export * type from './misc/GPUComputationRenderer.d.ts';
Static worker exited with code: 1 and signal: null
Error: Command "npm run build" exited with 1

Suggested solution:

I had to patch this back to -> export type * from './misc/xxxx.d.ts'; as "export * type from './misc/xxxx.d.ts';" is not valud exporting format.

try previous package npm i three-stdlib@2.35.7

i am not sure with three version but try this
"three-stdlib": "2.35.7",
"three": "^0.172.0",
"@react-three/drei": "^9.121.2",
"@react-three/fiber": "^8.17.12",
"@types/three": "^0.172.0",

@rosskevin
Copy link
Contributor

@CodyJasonBennett this is related to issue #342 and the fix in #343.

Image

@rosskevin
Copy link
Contributor

I'm taking a shot at the PR, if I can get the regex right...

@rosskevin
Copy link
Contributor

PR available #400

Copy link

github-actions bot commented Jan 19, 2025

🎉 This issue has been resolved in version 2.35.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants