TypeScript path aliases not working correctly #1685
-
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"],
"~/public/*": ["./public/*"]
},
alias: {
"~/*": "./src/*",
"~/public/*": "./public/*",
}, it behaves the same if I skip alias: {
"~": "./src",
"~/public": "./public",
},
import Preloader from "~/scenes/Preloader"; Snowpack output [snowpack] Error: Import "~/scenes/Preloader" could not be resolved.
If this import doesn't exist in the source file, add "install": ["~/scenes/Preloader"] to your Snowpack config file. Any ideas why this might be happening? mount: {
public: "/",
src: "/_dist_",
}, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I've also got this issue... |
Beta Was this translation helpful? Give feedback.
-
Did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
The following works, using Snowpack 3.0.5: /* eslint-env node */
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
public: "/",
src: "/_dist_",
},
plugins: ["@snowpack/plugin-typescript", "@snowpack/plugin-webpack"],
packageOptions: {
types: true,
},
devOptions: {
port: 8000,
},
buildOptions: {
out: "dist",
sourcemap: true,
},
alias: {
"~": "./src",
"~/public": "./public",
},
};
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"strict": true,
"noImplicitAny": false,
/* noEmit - We only use TypeScript for type checking. */
"noEmit": true,
"allowJs": true,
"importHelpers": true,
"importsNotUsedAsValues": "error",
/* more strict checking for errors that per-file transpilers like `esbuild` would crash */
"isolatedModules": true,
"skipLibCheck": true,
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"useDefineForClassFields": true,
"typeRoots": ["./node_modules/@types", "./src/types"],
"baseUrl": "./",
"paths": {
"~/*": ["./src/*"],
"~/public/*": ["./public/*"]
},
"types": ["phaser", "node"]
},
"include": ["src/**/*"]
} |
Beta Was this translation helpful? Give feedback.
-
It's not working for external folders as in lerna setup. I need import sibling package with |
Beta Was this translation helpful? Give feedback.
The following works, using Snowpack 3.0.5:
snowpack.config.js
tsconfig.json