Repository navigation
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript) #1627
Replies: 2 comments
|
help |
|
For that sibling-package layout, check both the TypeScript program and the plugin's file filter. A workspace dependency makes the import resolvable; it does not automatically make the sibling source pass the TypeScript plugin's filter. I reproduced the error with
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"rootDir": ".."
},
"include": ["src/**/*.ts", "../shared/src/**/*.ts"]
}
const typescript = require('@rollup/plugin-typescript');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
module.exports = {
input: 'src/A.ts',
output: { file: 'dist/bundle.cjs', format: 'cjs' },
plugins: [
nodeResolve({ extensions: ['.js', '.ts'] }),
typescript({
tsconfig: './tsconfig.json',
filterRoot: '..',
include: ['A/src/**/*.ts', 'shared/src/**/*.ts']
})
]
};Run Rollup from In the reproduction, adding the sibling to tsconfig alone still left its type annotation reaching Rollup's JS parser. With both sources included, The filterRoot documentation specifically covers files outside the current working directory. These checks used TypeScript 4.9.5, node-resolve 15.0.1, tslib 2.5.0 and Linux/Node 24.22.1, not your original macOS/Node 14 environment. Your full config isn't included, so this verifies one concrete cause and fix, not every possible cause of this parser error. |
Uh oh!
There was an error while loading. Please reload this page.
Expected Behavior
There are two sub projects in my project
/packages/A/src/**
/packages/shared/src/**
I referenced the shared project packages.json configuration in Project A as follows:
"devDependencies": {
"B": "workspace:*",
}
Project A refers to a method from Project shared, and I hope to build it normally
/projects/A/src/A.ts
/projects/A/rollup.config.js
/projects/shared/src/somemod.ts
// A.ts
import {theAnswer} from "shared/src/somemod";
console.log(theAnswer);
When I run the build in /projects/A/, the build failes with the described error.
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
Actual Behavior
During the actual process of building and packaging, I was constantly prompted:
[!] Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
I have already configured the relevant plugins and it is normal to directly include this method in project A. However, I envision a directory for storing public methods.
How can I solve this problem
Additional Information
All reactions