Syntax error: Unexpected token, expected "from" #6294

Closed
opened 2026-02-21 18:15:01 -05:00 by yindo · 6 comments
Owner

Originally created by @likenamehaojie on GitHub (Oct 24, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

main

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

⨯ ./middleware.ts:1:12
Syntax error: Unexpected token, expected "from"

1 | import type { NextRequest } from 'next/server';
| ^
2 | import { NextResponse } from 'next/server'
3 |
4 | const NECESSARY_DOMAIN = '.sentry.io http://localhost: http://127.0.0.1:* https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com'
TypeError: The "path" argument must be of type string. Received undefined

✔️ Expected Behavior

⨯ ./middleware.ts:1:12
Syntax error: Unexpected token, expected "from"

1 | import type { NextRequest } from 'next/server';
| ^
2 | import { NextResponse } from 'next/server'
3 |
4 | const NECESSARY_DOMAIN = '.sentry.io http://localhost: http://127.0.0.1:* https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com'
TypeError: The "path" argument must be of type string. Received undefined

Actual Behavior

⨯ ./middleware.ts:1:12
Syntax error: Unexpected token, expected "from"

1 | import type { NextRequest } from 'next/server';
| ^
2 | import { NextResponse } from 'next/server'
3 |
4 | const NECESSARY_DOMAIN = '.sentry.io http://localhost: http://127.0.0.1:* https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com'
TypeError: The "path" argument must be of type string. Received undefined

Originally created by @likenamehaojie on GitHub (Oct 24, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version main ### Cloud or Self Hosted Self Hosted (Source) ### Steps to reproduce ⨯ ./middleware.ts:1:12 Syntax error: Unexpected token, expected "from" > 1 | import type { NextRequest } from 'next/server'; | ^ 2 | import { NextResponse } from 'next/server' 3 | 4 | const NECESSARY_DOMAIN = '*.sentry.io http://localhost:* http://127.0.0.1:* https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com' TypeError: The "path" argument must be of type string. Received undefined ### ✔️ Expected Behavior ⨯ ./middleware.ts:1:12 Syntax error: Unexpected token, expected "from" > 1 | import type { NextRequest } from 'next/server'; | ^ 2 | import { NextResponse } from 'next/server' 3 | 4 | const NECESSARY_DOMAIN = '*.sentry.io http://localhost:* http://127.0.0.1:* https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com' TypeError: The "path" argument must be of type string. Received undefined ### ❌ Actual Behavior ⨯ ./middleware.ts:1:12 Syntax error: Unexpected token, expected "from" > 1 | import type { NextRequest } from 'next/server'; | ^ 2 | import { NextResponse } from 'next/server' 3 | 4 | const NECESSARY_DOMAIN = '*.sentry.io http://localhost:* http://127.0.0.1:* https://analytics.google.com googletagmanager.com *.googletagmanager.com https://www.google-analytics.com https://api.github.com' TypeError: The "path" argument must be of type string. Received undefined
yindo added the 🤔 cant-reproduce label 2026-02-21 18:15:01 -05:00
yindo closed this issue 2026-02-21 18:15:01 -05:00
Author
Owner

@likenamehaojie commented on GitHub (Oct 24, 2024):

@crazywoola

@likenamehaojie commented on GitHub (Oct 24, 2024): @crazywoola
Author
Owner

@dosubot[bot] commented on GitHub (Oct 24, 2024):

The syntax error you're encountering, "Unexpected token, expected 'from'", typically occurs when the TypeScript compiler or the environment is not correctly set up to handle the import type syntax. Here are a few steps to troubleshoot and resolve this issue:

  1. Check TypeScript Version: Ensure that you are using a TypeScript version that supports the import type syntax. This feature is available from TypeScript 3.8 onwards.

  2. Verify tsconfig.json Configuration: Make sure your tsconfig.json is correctly configured to support modern TypeScript features. The module option should be set to "esnext" or a compatible module system that supports import type. Here's a relevant snippet from the Dify project's tsconfig.json:

    {
      "compilerOptions": {
        "module": "esnext",
        // other options...
      }
    }
    
  3. Check Build Tools: If you're using a build tool like Babel or Webpack, ensure that it is configured to handle TypeScript and the import type syntax. You might need to update your Babel configuration or ensure that the TypeScript loader is correctly set up in Webpack.

  4. Environment Setup: Ensure that your development environment is using the correct Node.js and NPM versions as specified by the Dify project. The project requires Node.js version v18.x (LTS) and NPM version 8.x.x [1].

By verifying these configurations, you should be able to resolve the syntax error related to the import type statement. If the issue persists, consider checking for any additional configuration or compatibility issues with your specific setup.

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Oct 24, 2024): <!-- Answer --> The syntax error you're encountering, "Unexpected token, expected 'from'", typically occurs when the TypeScript compiler or the environment is not correctly set up to handle the `import type` syntax. Here are a few steps to troubleshoot and resolve this issue: 1. **Check TypeScript Version**: Ensure that you are using a TypeScript version that supports the `import type` syntax. This feature is available from TypeScript 3.8 onwards. 2. **Verify `tsconfig.json` Configuration**: Make sure your `tsconfig.json` is correctly configured to support modern TypeScript features. The `module` option should be set to `"esnext"` or a compatible module system that supports `import type`. Here's a relevant snippet from the Dify project's `tsconfig.json`: ```json { "compilerOptions": { "module": "esnext", // other options... } } ``` 3. **Check Build Tools**: If you're using a build tool like Babel or Webpack, ensure that it is configured to handle TypeScript and the `import type` syntax. You might need to update your Babel configuration or ensure that the TypeScript loader is correctly set up in Webpack. 4. **Environment Setup**: Ensure that your development environment is using the correct Node.js and NPM versions as specified by the Dify project. The project requires Node.js version `v18.x (LTS)` and NPM version `8.x.x` <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/package.json)</sup>. By verifying these configurations, you should be able to resolve the syntax error related to the `import type` statement. If the issue persists, consider checking for any additional configuration or compatibility issues with your specific setup. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Oct 24, 2024):

Not able to reproduce this problem

~/Program/dify/web (main) » yarn dev                                                                                                                                
yarn run v1.22.19
$ next dev
  ▲ Next.js 14.2.10
  - Local:        http://localhost:3000
  - Environments: .env

 ✓ Starting...
   Disabled SWC as replacement for Babel because of custom Babel configuration "babel.config.js" https://nextjs.org/docs/messages/swc-disabled
   automatically enabled Fast Refresh for 1 custom loader
 ✓ Ready in 5.1s
@crazywoola commented on GitHub (Oct 24, 2024): Not able to reproduce this problem ```bash ~/Program/dify/web (main) » yarn dev yarn run v1.22.19 $ next dev ▲ Next.js 14.2.10 - Local: http://localhost:3000 - Environments: .env ✓ Starting... Disabled SWC as replacement for Babel because of custom Babel configuration "babel.config.js" https://nextjs.org/docs/messages/swc-disabled automatically enabled Fast Refresh for 1 custom loader ✓ Ready in 5.1s ```
Author
Owner

@likenamehaojie commented on GitHub (Oct 24, 2024):

要访问下页面才会报错
localhost:3000
@crazywoola

@likenamehaojie commented on GitHub (Oct 24, 2024): 要访问下页面才会报错 localhost:3000 @crazywoola
Author
Owner

@mayiming0708 commented on GitHub (Oct 24, 2024):

the same problem when run npm build , delete babel.config.js success

@mayiming0708 commented on GitHub (Oct 24, 2024): the same problem when run `npm build` , delete `babel.config.js` success
Author
Owner

@likenamehaojie commented on GitHub (Oct 24, 2024):

@mayiming0708 thanks! @crazywoola babel.config.js Can this file be deleted? After deleting it, the issue was resolved. Will it affect other functionalities?

@likenamehaojie commented on GitHub (Oct 24, 2024): @mayiming0708 thanks! @crazywoola babel.config.js Can this file be deleted? After deleting it, the issue was resolved. Will it affect other functionalities?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#6294