Use absolute imports in Next.js app deployed with ZEIT Now

前端 未结 3 1645
野趣味
野趣味 2021-01-02 11:04

In the Next.js 9 tutorial the suggested way to import shared components is by relative paths, like

import Header from          


        
3条回答
  •  猫巷女王i
    2021-01-02 12:02

    In Next.js 9.4 it is possible to do it by adding the baseUrl config to jsconfig.json (JS projects) or tsconfig.json (TS projects).

    // jsconfig.json or tsconfig.json
    {
      "compilerOptions": {
        "baseUrl": "."
      }
    }
    

    This will allow imports from the root directory. It also integrates well with IDE such as VS Code. See documentation for more information.

提交回复
热议问题