-
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
Unable to import ts-files outside of project dir #20374
Comments
So I figured this out. If I add module.exports = {
webpack: (config) => {
config.module.rules.push({
test: /\.tsx?$/,
use: ["ts-loader"],
})
return config
},
} I also have to set Now, something else is happening. Whenever I import
This results in a hard crash of next-js. What do I do? |
So, as you can see from above, it's actually looking for a file named "util" in the repo root. I don't understand why, but I tried creating it:
Now it crashes on another file. Let's create all of them: touch util
touch events
touch assert
touch buffer
touch querystring
touch url Suddenly it doesn't crash anymore, but now it does this instead:
I absolutely have no clue what's going on. |
So I found the reason for the crash: next.js/packages/next/build/webpack-config.ts Line 659 in a9f1975
Removing the I'm still getting the odd warnings, but it's running as it should, it seems. |
…of the root directory (#22867) This PR attempts to provide an option to allow importing TS/TSX from outside of the current Next.js project root directory. Although this goes against the design decision that no source code should be imported from outside of root and [might bring tons of issues](#19928 (comment)), it will still be helpful in some monorepo use cases. This PR assumes that the external files are following the same language syntax rules and under the same tooling versions as the source code inside your project root. And it's also not allowed to enable the `baseUrl` feature in the external directory (as the project should only have 1 import base URL). X-ref: #9474, #15569, #19928, #20374.
…of the root directory (vercel#22867) This PR attempts to provide an option to allow importing TS/TSX from outside of the current Next.js project root directory. Although this goes against the design decision that no source code should be imported from outside of root and [might bring tons of issues](vercel#19928 (comment)), it will still be helpful in some monorepo use cases. This PR assumes that the external files are following the same language syntax rules and under the same tooling versions as the source code inside your project root. And it's also not allowed to enable the `baseUrl` feature in the external directory (as the project should only have 1 import base URL). X-ref: vercel#9474, vercel#15569, vercel#19928, vercel#20374.
We've landed an experimental feature for this: #22867 |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
I have three projects; A, B and C. C is the "common" project that is used by both A (next-js) and B (pure ts using
tsc
). C transpiles fine, as does B.Importing code from C in project A (next-js) gives syntax errors, as if the .ts-files are not being treated as TypeScript:
Module parse failed: Unexpected token (62:58)
The unexpected token happens to be a colon denoting a type (i.e.,
varName: ...
). It works and imorts fine from B and it's definitely a valid TS source file.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Add the following just under "import styles ..." in pages/index.js:
Add this to my-app/tsconfig.json:
Add this as b/tsconfig.json:
Visit localhost:3000
Check error in terminal:
Expected behavior
The app imports foo.ts and runs fine.
Screenshots
System information
Browser:npm run dev
Additional context
n/a
The text was updated successfully, but these errors were encountered: