I'm currently experiencing difficulty importing a file from the rails asset pipeline as webpack seems to be unable to locate it.
Here is the content of my tsconfig.json:
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"baseUrl": ".",
"paths": {
"@images/*": ["app/assets/images/*"],
}
},
"exclude": [
"**/*.spec.ts",
"node_modules",
"vendor",
"public"
],
"compileOnSave": false
}
This is the content of my config/webpack/environment.js:
const { environment } = require('@rails/webpacker')
const customConfig = require('./custom');
const typescript = require('./loaders/typescript')
const fileLoader = require('./loaders/file');
environment.loaders.append('file', fileLoader)
environment.loaders.append('typescript', typescript)
// Merge custom config
environment.config.merge(customConfig);
module.exports = environment
My config/webpack/custom.js looks like this:
const path = require('path');
module.exports = {
resolve: {
alias: {
'@src': path.resolve(__dirname, '..', '..', 'app/javascript'),
'@images': path.resolve(__dirname, '..', '..', 'app/assets/images'),
'@components': '@src/components',
React: 'react',
ReactDOM: 'react-dom'
}
}
};
import "@images/ajax-circle.gif";
in one of my typescript files is triggering error 2307 (module resolution failure) and webpack-dev-server
is unable to compile due to the following error:
ERROR in /Users/brandoncc/dev/my_app/app/javascript/lib/store_management.ts
[tsl] ERROR in /Users/brandoncc/dev/my_app/app/javascript/lib/store_management.ts(1,24)
TS2307: Cannot find module '@images/ajax-circle.gif'.
webpack: Failed to compile.
It appears that typescript is struggling to locate the file, and I am struggling to identify the root cause of this issue.