Skip to content

error running tsc command: SyntaxError: Cannot use import statement outside a module #8

Open
@samanshahmohamadi

Description

@samanshahmohamadi

Hi
This is stack is doing good in writing tests for smart contracts. I managed to migrate my project to Buidler+Ethers stack via this starter kit. That's amazing.
But now, I'm trying to bring express into project to have some http endpoints to interact with solidity functions. I'm using another starter kit express-typescript-starter and it needs to run tsc command which throws error when compiling buidler.config.ts file. Here is the error message:

import { BuidlerConfig, usePlugin } from "@nomiclabs/buidler/config";
^^^^^^
SyntaxError: Cannot use import statement outside a module

There is no way to tell the tsc command to ignore the config file.
I know that this issue is not directly related to this repo, but it may help to adapt it with real use-cases.
Thanks.

Package.json

{
  "name": "solidity-ts-dev-stack-example",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "npm run build && npm run serve",
    "build": "npm run build-ts",
    "serve": "node dist/src/server.js",
    "watch-node": "nodemon dist/server.js",
    "watch": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run watch-node\"",
    "watch-test": "npm run test -- --watchAll",
    "build-ts": "tsc",
    "watch-ts": "tsc -w",
    "build-sass": "node-sass src/public/css/main.scss dist/public/css/main.css",
    "watch-sass": "node-sass -w src/public/css/main.scss dist/public/css/main.css",
    "lint": "tsc --noEmit && eslint \"**/*.{js,ts}\" --quiet --fix",
    "copy-static-assets": "ts-node copyStaticAssets.ts",
    "debug": "npm run build && npm run watch-debug",
    "serve-debug": "nodemon --inspect dist/server.js",
    "watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\"",
    "buidler:build": "npm run buidler:compile && npx buidler typechain",
    "buidler:compile": "npx buidler compile",
    "buidler:test": "npx buidler test",
    "buidler:coverage": "npm run buidler:build && npx buidler coverage --temp artifacts --network coverage",
    "buidler:typechain": "./node_modules/.bin/typechain --target ethers --outDir src/types 'artifacts/*.json'"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/rhlsthrm/solidity-ts-dev-stack-example.git"
  },
  "author": "rhlsthrm",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/rhlsthrm/solidity-ts-dev-stack-example/issues"
  },
  "homepage": "https://github.com/rhlsthrm/solidity-ts-dev-stack-example#readme",
  "devDependencies": {
    "@nomiclabs/buidler": "^1.1.2",
    "@nomiclabs/buidler-ethers": "^1.1.2",
    "@nomiclabs/buidler-etherscan": "^1.1.2",
    "@nomiclabs/buidler-waffle": "^1.1.2",
    "@types/chai": "^4.2.11",
    "@types/mocha": "^7.0.1",
    "@types/node": "^13.7.0",
    "buidler-typechain": "0.0.5",
    "chai": "^4.2.0",
    "ethereum-waffle": "^2.3.2",
    "ethers": "^4.0.44",
    "solidity-coverage": "^0.7.1",
    "ts-generator": "0.0.8",
    "ts-node": "^8.6.2",
    "typechain": "^1.0.4",
    "typechain-target-ethers": "^1.0.3",
    "typechain-target-truffle": "^1.0.2",
    "typechain-target-web3-v1": "^1.0.4",
    "typescript": "^3.7.5"
  },
  "dependencies": {
    "async": "^3.1.0",
    "bcrypt-nodejs": "^0.0.3",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "dotenv": "^8.2.0",
    "errorhandler": "^1.5.1",
    "express": "^4.17.1",
    "express-validator": "^6.2.0",
    "lodash": "^4.17.15",
    "lusca": "^1.6.1",
    "nodemailer": "^6.3.0",
    "winston": "^3.2.1",
    "config": "latest",
    "@types/async": "^3.0.2",
    "@types/bcrypt-nodejs": "^0.0.30",
    "@types/bignumber.js": "^5.0.0",
    "@types/bluebird": "^3.5.27",
    "@types/body-parser": "^1.17.1",
    "@types/compression": "^1.0.1",
    "@types/concurrently": "^4.1.0",
    "@types/errorhandler": "^0.0.32",
    "@types/eslint": "^6.1.1",
    "@types/express": "^4.17.1",
    "@types/express-flash": "0.0.1",
    "@types/express-session": "^1.15.14",
    "@types/lodash": "^4.14.141",
    "@types/lusca": "^1.6.1",
    "@types/shelljs": "^0.8.5",
    "@types/supertest": "^2.0.8",
    "@types/winston": "^2.4.4",
    "@typescript-eslint/eslint-plugin": "^2.3.1",
    "@typescript-eslint/parser": "^2.3.1",
    "babel-register": "^6.26.0",
    "concurrently": "^5.0.0",
    "eslint": "^6.4.0",
    "ethereumjs-common": "latest",
    "ethereumjs-tx": "latest",
    "nodemon": "^1.19.2",
    "shelljs": "^0.8.3",
    "supertest": "^4.0.2",
    "ts-generator": "^0.0.8",
    "ts-node": "^8.10.1",
    "typechain": "1.0.5",
    "truffle-typings": "1.0.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "outDir": "dist",
    "resolveJsonModule": true,
    "moduleResolution": "node"
  },
  "include": [
    "src/**/*",
    "./scripts",
    "./test"
  ],
  "files": [
    "./buidler.config.ts",
    "node_modules/@nomiclabs/buidler-ethers/src/type-extensions.d.ts",
    "node_modules/@nomiclabs/buidler-etherscan/src/type-extensions.d.ts",
    "node_modules/@nomiclabs/buidler-waffle/src/type-extensions.d.ts",
    "node_modules/buidler-typechain/src/type-extensions.d.ts"
  ],
  "exclude": [
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions