新建vue3项目之后,手动把main.js重命名main.ts之后,启动项目报错Module not found: Error: Can't resolve './src/main.js',很明显是找不到main.js这个文件,我全局搜索根本没有用到main.js,查了一下发现可能是配置文件或者创建项目时在某些隐藏文件中使用了main.js;
解决办法:
1.如果全局搜索有main.js,则全部替换成main.ts;
2.如果上一个方法还是没用,查看项目是否支持ts,使用npm install typescript --save-dev命令,下载 TypeScript,使用npx tsc运行ts,新建tsconfig.json
配置文件,确保您的项目的 tsconfig.json
文件配置正确;
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
"suppressImplicitAnyIndexErrors": true,
"strictPropertyInitialization": false,
"downlevelIteration": true,
"noUnusedLocals": false,
"noImplicitAny": false,
"noImplicitThis": true,
"removeComments": false,
"strictFunctionTypes": false,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules",
"dist"
]
}
3.如果还是没用,在vue.config.js中指定main.ts;
module.exports = {
pages: {
index: {
entry:'src/main.ts',
},
},
};
到最后一步差不多就可以了