我一直在浏览所有其他帖子,以了解react / typescript项目中的相同问题,但这些都不对我有用...甚至ts.config或将noImplicitAny更改为false并将strict严格更改为false都没有“排除”和“ typeRoots”。
我尝试声明一个模块,尝试将其放在.d.ts文件中,尝试使用@ ts-ignore,但我什么都无法工作。这让我发疯了……有人可以告诉我如何一劳永逸地解决这个问题,以便我可以正确地编译它吗?
index.js文件中存在很多相同类型的问题,但是一旦有很多要求抛出相同的问题,但是一旦我解决了这个问题,我也应该能够修复其他问题。
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['rest/index'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS-like environments that support module.exports, like Node.
module.exports = factory(require('./rest/index')); **<---- ERROR HERE**
}
}(function(restIndex) {
return restIndex;
}));
编辑: Client.js:
var apiKey = process.env.ROCKSET_APIKEY;
var apiServer = process.env.ROCKSET_APISERVER;
var rockset = require('rockset')(apiKey, apiServer);
var getResponseLogger = function(callback) {
return function(error, response, body) {
if(error) {
console.log(error.response.error.text);
callback();
} else {
console.log(response);
callback();
}
}
}
export function getMaxSkill() {
rockset.queries.query({
'sql': {
'query': 'select * from "testCollection"'
}
}, null, getResponseLogger(done))
}
function done() {
console.log('\n\n===done===');
}
App.tsx:
import {getMaxSkill} from './client';
async componentDidMount() {
getMaxSkill();
}
tsconfig
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"typeRoots": [
"../../@types",
"../../node_modules/@types"
]
},
"include": [
"src", "tests/App.test.js"
],
"paths": {
"@material-ui/core": ["./material-ui/src"],
"@material-ui/core/*": ["./material-ui/src/*"],
"@material-ui/lab": ["./material-ui-lab/src"],
"@material-ui/lab/*": ["./material-ui-lab/src/*"],
"@material-ui/styles": ["./material-ui-styles/src"],
"@material-ui/styles/*": ["./material-ui-styles/src/*"],
"@material-ui/system": ["./material-ui-system/src"],
"@material-ui/types": ["./material-ui-types"]
}
}