I'm seeing the error I specified in my title and none of the existing solutions here seem to help, so I'm hoping someone can give me insight as to what is going on.
I am using Typescript and Node in my project. TS compiles everything just fine...I end up with the following as expected:
projectHome/
dist/
schema/
schema.js
index.js
When I run node ./dist/index.js from project home, I get the error
cannot find module '/home/me/projectHome/dist/schema/schema' imported from '/home/me/projectHome/dist/index.js'
Relative imports in index.js are as follows:
import express from 'express';
import { ApolloServer } from 'apollo-server-express';
import typeDefs from './schema/schema';
My schema.ts file contains:
import { ApolloServer, gql } from 'apollo-server-express'
import { GraphQLScalarType } from 'graphql'
const typeDefs = gql`
...(edited for brevity/sanity)
`
export default typeDefs
and my typescript file (should this matter at this point since it is Node that is failing??) looks like this:
{
"compilerOptions": {
"target": "ES6",
"module": "ES6",
"lib": ["ES6"],
"allowJs": true,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"files": ["src/@types/graphql.d.ts"],
"include": ["src/**/*", "serverInfo.json"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Note that I cannot use commonjs because some objection related code fails when I do. Is the problem actually related to using ES6 modules, or is something else wrong?
Thank in advance!
-Chris