paths are not being rewritten after compilation
See original GitHub issueNo matter what I seem to try, the values defined in paths
in my tsconfig.json
file are not being transformed by tsconfig-paths
, which results in node being unable to resolves any modules.
Giving an example, where I would expect @graphql-handlers
imports in my ts files to be converted to graphql-handlers
in my compiled .js… but when you examine the output in the dist
folder, all of the paths still show @graphql-handlers
which renders node unable to run.
tsconfig.json
// https://www.typescriptlang.org/tsconfig
{
"compilerOptions": {
"target": "ES6",
"moduleResolution": "node",
"baseUrl": "src",
"esModuleInterop": true,
"outDir": "dist",
"sourceMap": true,
"noEmit": false,
"paths": {
"@graphql-handlers": [ "graphql-handlers" ],
}
},
"include": [
"src"
],
"exclude": ["node_modules"],
"typeRoots": [
"src/@types",
]
}
package.json
{
"name": "xxxxxxx",
"version": "2.0.0",
"description": "xxxxxxxxxxxx",
"main": "src/index.js",
"scripts": {
"compile": "rm -rf ./dist; tsc",
"boot": "node dist/src/index.js",
"watch": "tsc-watch --onSuccess \"npm run boot\"",
"test": "node node_modules/.bin/jest --coverage"
},
"type": "module",
"author": "xxxxxxxxxxxx",
"license": "UNLICENSED",
"dependencies": {
"apollo-server-core": "^3.10.0",
"apollo-server-express": "^3.10.0",
"bcryptjs": "^2.4.3",
"express": "^4.18.1",
"express-graphql": "^0.12.0",
"express-jwt": "^7.7.5",
"graphql": "^15.8.0",
"jsonwebtoken": "^8.5.1",
"oracledb": "^5.4.0"
},
"devDependencies": {
"@babel/core": "^7.18.6",
"@babel/preset-env": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@faker-js/faker": "^7.3.0",
"@types/express": "^4.17.13",
"@types/jest": "^28.1.6",
"@types/oracledb": "^5.2.3",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"babel-jest": "^29.0.3",
"eslint": "^8.19.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"jest": "^28.1.2",
"supertest": "^6.2.4",
"ts-node": "^10.9.1",
"tsc-watch": "^5.0.3",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.7.4"
}
}
index.ts
import { bootServer } from './server.js';
import resolver from '@graphql-handlers/login/resolvers.js';
import loginTypes from '@graphql-handlers/login/schema.js';
import types from '@graphql-handlers/types.js';
import centerOutcomeSchema from '@graphql-handlers/centerOutcomes/schema.js';
const port = process.env.PORT;
const dbConn = null;
bootServer([types, loginTypes, centerOutcomeSchema], [resolver], port, dbConn);
Run command: rm -rf dist; npm run compile; node_modules/.bin/ts-node -r tsconfig-paths/register dist/index.js
Error output:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@/graphql-handlers' imported from /app/api/dist/index.js
Did you mean to import /app/api/dist/graphql-handlers/login/resolvers.js?
at new NodeError (node:internal/errors:388:5)
at packageResolve (node:internal/modules/esm/resolve:910:9)
at moduleResolve (node:internal/modules/esm/resolve:959:20)
at defaultResolve (node:internal/modules/esm/resolve:1174:11)
at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18) at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
at link (node:internal/modules/esm/module_job:78:36) {
code: 'ERR_MODULE_NOT_FOUND'
}
Looking at the compiled output in dist/index.js, @graphql-handlers has not been converted:
import { bootServer } from './server.js';
import resolver from '@graphql-handlers/login/resolvers.js';
import loginTypes from '@graphql-handlers/login/schema.js';
import types from '@graphql-handlers/types.js';
import centerOutcomeSchema from '@graphql-handlers/centerOutcomes/schema.js';
const port = process.env.PORT;
const dbConn = null;
bootServer([types, loginTypes, centerOutcomeSchema], [resolver], port, dbConn);
//# sourceMappingURL=index.js.map
Issue Analytics
- State:
- Created a year ago
- Comments:8
Top Results From Across the Web
Why are these tsconfig paths not working? - Stack Overflow
In case anyone is using VSCode and having trouble getting the /* solution to work. Try Cmd+Shift+P > Typescript: Restart TS Server. –...
Read more >LESS compiling doesn't seem to handle a relative path correctly
This is caused by 6156a6b, which completely fails on relative paths that traverse higher than the root LESS file. Reverting that will fix...
Read more >URL Rewrite not working only for one specific path
Since it is only about single URL rewrite issue you should try below steps if it works for you. In Admin go to...
Read more >1.1. Compiling and Executing Programs
Non -header files should declare only things that do not need to be shared. As we go through all the compilation steps required...
Read more >mod_rewrite - Apache HTTP Server Version 2.4
The path generated by a rewrite rule can include a query string, ... This value has not been unescaped (decoded), unlike most other...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I used
resolve-tspaths
as part of the build step (ie."build": "tsc && resolve-tspaths"
).This was the easiest and most straight forward solution for my needs. Thanks @kendallroth !