Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript getting error TS2304 cannot find name ' require' #131

Open
deepthan opened this issue Feb 22, 2021 · 0 comments
Open

typescript getting error TS2304 cannot find name ' require' #131

deepthan opened this issue Feb 22, 2021 · 0 comments

Comments

@deepthan
Copy link
Owner

在angular项目的环境配置的时候,使用require引入其他文件报此错误。

export const environment = Object.assign({}, require('./common.json'), require('./production.json'), {
  production: true,
  envName: 'prod'
});

这是因为在typescript2.x中,我们还需要做:

  • 下载定义require的包
npm install @types/node --save-dev
  • tsconfig.app.json中配置这个包为全局的
{
    "compilerOptions": {
        "types": ["node"]
    }
}

再次运行即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant