I'm having a hard time figuring out how to do this. My environment is:
- Node.js 16.1.x
- Vue.js 3.x
- TypeScript 4.2.4
My directory structure is like this:
- Root (Node.js server)
- shared
- MySharedFile.ts
- ui (Vue.js code)
- shared
MySharedFile.ts is exporting a very simple module:
export const MyShared = {
TEST: 1
};
In Vue.js, I'm trying to import this module import {MyShared} from '../../shared/MySharedFile', but when the app builds, I get the error Parsing error: 'import' and 'export' may appear only with 'sourceType: module'. I've searched and found a thread that suggests changing the eslintrc settings, which didn't work. This error really doesn't make sense to me, so what does it mean, and how can I fix it?
ui/tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"outDir": "./dist",
// https://github.com/TypeStrong/ts-loader/issues/1138
"importsNotUsedAsValues": "preserve",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"es2020",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
ui/.eslintrc.js
module.exports = {
root: true,
env: {
node: true
},
extends: [
'@vue/typescript',
'plugin:vue/vue3-recommended',
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/typescript/recommended'
],
parserOptions: {
ecmaVersion: 11,
sourceType: 'module',
allowImportExportEverywhere: true
}
}
For anyone wanting the source code... I'm now at a new error Parsing error: ‘import’ and ‘export’ may appear only with ‘sourceType: module’