English 中文(简体)
为什么我拿到“碎片不是模块”字典中的错误
原标题:Why am I getting "File is not a module" error in TypeScript

我在这项法典上太长了,我无法指出,为什么我错了,这不是一个单元。

档案名称:网页.tsx

import Link from "next/link";
import SessionList from "./sessionList";

export default function Page() {

    return (
        <article>
            <div className="flex justify-between items-center mb-3">
                <h2 className="p-0 m-0">Session List</h2>
                <Link href="/sessions/edit" className="bg-rr-green px-3 py-1 rounded-lg text-white">Add New</Link>
            </div>
            <SessionList />
        </article>
    )
}

这是一个由Tailwind、Austh0和MongoDB运行的下一个JS项目。 我正在使用Aus0作认证,在姐妹地点没有问题。 唯一的区别是,我把奥特0装在布局。 ts作为服务器组成部分。 我可以操作<代码>npm, dev, 申请工作罚款。 但是,当我努力建设时,我得到以下信息:

.next/types/app/sessions/edit/page.ts:2:24
Type error: File  C:/Users/shane/workspaces/riverrail-admin/app/sessions/edit/page.tsx  is not a module.

  1 | // File: C:Usersshaneworkspaces
iverrail-adminappsessionseditpage.tsx
> 2 | import * as entry from  ../../../../../app/sessions/edit/page.js 
    |                        ^
  3 | import type { ResolvingMetadata, ResolvingViewport } from  next/dist/lib/metadata/types/metadata-interface.js 
  4 |
  5 | type TEntry = typeof import( ../../../../../app/sessions/edit/page.js )

我失踪了什么?

我已尝试去除盒子,删除所有节点模块,并重新安装<代码>npm >。 我看不到任何错误。

Here is my package.json file:

{
  "name": "riverrail-admin",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@auth0/nextjs-auth0": "^3.5.0",
    "@ckeditor/ckeditor5-alignment": "^41.3.1",
    "@ckeditor/ckeditor5-build-classic": "^41.3.1",
    "@ckeditor/ckeditor5-react": "^6.2.0",
    "@vercel/analytics": "^1.2.2",
    "html-react-parser": "^5.1.10",
    "mongodb": "^6.5.0",
    "next": "14.1.4",
    "react": "^18",
    "react-dom": "^18",
    "react-icons": "^5.1.0"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10.0.1",
    "eslint": "^8",
    "eslint-config-next": "14.1.4",
    "postcss": "^8",
    "tailwindcss": "^3.3.0",
    "typescript": "^5"
  }
}
问题回答

file is not a module error comes when type in package.json file is commonJs(default value) and you try to use modules using import statement instead of require method. So you need to change type in the package.json file to module only.





相关问题
Access DB Ref MongoDB

Whats the best way to access/query a DB Ref: UPDATE: users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } } groups: name, topic, country,...,.. Assumption is that user belongs to only one ...

MongoDB nested sets

What re the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

Storing and accessing large amounts of data

My application creates pieces of data that, in xml, would look like this: <resource url="someurl"> <term> <name>somename</name> <frequency>somenumber</...

热门标签