-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
absolute paths causes error on windows OS #4730
Comments
adding |
Can you share more info, like the config to |
@kdy1 you can use same config above with transform import { transformSync } from '@swc/core'
import { join } from 'path'
const content = `
import { displayB } from '@print/b'
async function display() {
const displayA = await import('@print/a').then(c => c.displayA)
console.log(displayA())
console.log(displayB())
}
display()
`
const { code } = transformSync(content, {
"jsc": {
"parser": {
"syntax": "typescript",
"dynamicImport": true
},
"target": "es2020",
"paths": {
"@print/a": [
join(process.cwd(), "./packages/a/src/index.ts")
],
"@print/b": [
join(process.cwd(), "./packages/b/src/index.ts")
]
}
},
"module": {
"type": "commonjs"
}
})
console.log(code) Output "use strict";
var _b = require("C:\\dev\\packages\\b\\src\\index.ts");
function _getRequireWildcardCache() {
if (typeof WeakMap !== "function") return null;
var cache = new WeakMap();
_getRequireWildcardCache = function() {
return cache;
};
return cache;
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
async function display() {
const displayA = await Promise.resolve().then(function() {
return _interopRequireWildcard(require("C:\\dev\\packages\\a\\src\\index.ts"));
}).then((c)=>c.displayA);
console.log(displayA());
console.log((0, _b).displayB());
}
display(); Expected "use strict";
var _b = require("C:\\dev\\packages\\b\\src\\index.ts");
function _getRequireWildcardCache() {
if (typeof WeakMap !== "function") return null;
var cache = new WeakMap();
_getRequireWildcardCache = function() {
return cache;
};
return cache;
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache();
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
async function display() {
const displayA = await Promise.resolve().then(function() {
return _interopRequireWildcard(require("C:\\dev\\packages\\a\\src\\index.ts"));
}).then((c)=>c.displayA);
console.log(displayA());
console.log((0, _b).displayB());
}
display(); |
Seems like you make a mistake while copy-pasting expected output or actual output? |
if you notice the |
I searched by copying the path and it was identical |
Oh your config is wrong. |
yes adding baseUrl same issue. |
or maybe i missed how does the paths works with |
anyway thanks for looking into it, i understand if this is not a priority, by the way thanks for |
I don't remember. |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
when the paths are full path or absolute path it causes error when running in Windows
Note: it works on MacOSX
transformSync
andbundle
has same behaviorInput code
./src/index.ts
./packages/a/src/index.s
./packages/b/src/index.s
transform.ts
The text was updated successfully, but these errors were encountered: