Skip to content
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

Copy symlinked module and transpile symlinked Typescript files #963

Closed
zirkelc opened this issue Sep 24, 2021 · 3 comments
Closed

Copy symlinked module and transpile symlinked Typescript files #963

zirkelc opened this issue Sep 24, 2021 · 3 comments
Labels
awaiting reply Awaiting for a reply from the OP

Comments

@zirkelc
Copy link

zirkelc commented Sep 24, 2021

This is a Bug

Description

I'm using Lerna to add a local package @abc/foundation as dependency to my other package @abc/connector. Lerna creates a symlink inside ./connector/node_modules which links to ../foundation/. In webpack.config.js I use externals: [nodeExternals() to copy all node_modules to .webpack to avoid the issues with npm install (#580 (comment)).

sls package then throws the following error:

Serverless: Packing external modules:  @abc/foundation@1.0.0, ...
 
 Exception -----------------------------------------------
 
  [OperationalError: ENOENT: no such file or directory, stat '/Users/chris/Projects/abc/connector/.webpack/dependencies/node_modules/@abc/foundation'] {
    cause: [Error: ENOENT: no such file or directory, stat '/Users/chris/Projects/abc/connector/.webpack/dependencies/node_modules/@abc/foundation'] {
      errno: -2,
      code: 'ENOENT',
      syscall: 'stat',
      path: '/Users/chris/Projects/abc/connector/.webpack/dependencies/node_modules/@abc/foundation'
    },
    isOperational: true,
    errno: -2,
    code: 'ENOENT',
    syscall: 'stat',
    path: '/Users/chris/Projects/abc/connector/.webpack/dependencies/node_modules/@abc/foundation'
  }

It seems like the symlink is broken when it is copied to the .webpack folder. I looks like the symlink is referencing itself.

I tried to change the webpack externals to allow my project name externals: [nodeExternals({ allowlist: [/^@abc/] }) as recommended in this issue #201 (comment)

This will end up in a webpack compilation error as webpack has no loader configured to transpiled Typescript files inside nodule_modules folder:

ERROR in ./node_modules/@abc/foundation/src/libs/secretsManager.ts 3:7
Module parse failed: Unexpected token (3:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

webpack.config.js

module.exports = {
	context: __dirname,
	mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
	entry: slsw.lib.entries,
	devtool: slsw.lib.webpack.isLocal ? 'eval-cheap-module-source-map' : 'source-map',
	resolve: {
		extensions: ['.mjs', '.json', '.ts'],
		symlinks: false,
		cacheWithContext: false
	},
	output: {
		libraryTarget: 'commonjs',
		path: path.join(__dirname, '.webpack'),
		filename: '[name].js'
	},
	optimization: {
		concatenateModules: false
	},
	target: 'node',
	externals: [
		//nodeExternals(),
		nodeExternals({ allowlist: [/^@abc/] }),
	], 
	module: {
		rules: [
			// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
			{
				test: /\.(tsx?)$/,
				loader: 'ts-loader',
				exclude: [
					[
						path.resolve(__dirname, 'node_modules'),
						path.resolve(__dirname, '.serverless'),
						path.resolve(__dirname, '.webpack')
					]
				],
				options: {
					transpileOnly: true,
					experimentalWatchApi: true
				}
			}
		]
	},
	plugins: [
		// new ForkTsCheckerWebpackPlugin({
		//   eslint: true,
		//   eslintOptions: {
		//     cache: true
		//   }
		// })
	]
};

Similar or dependent issue(s):

Additional Data

    "serverless": "^2.17.0",
    "serverless-webpack": "^5.2.0",
    "ts-loader": "^8.0.10",
    "ts-node": "^9.0.0",
    "typescript": "^4.0.5",
    "webpack": "^5.4.0",
    "webpack-node-externals": "^2.5.2"
@vicary
Copy link
Member

vicary commented Nov 19, 2021

@zirkelc If I am reading this correctly, this sounds like a webpack issue more than serverless-webpack.

@vicary vicary added the awaiting reply Awaiting for a reply from the OP label Nov 19, 2021
@j0k3r j0k3r closed this as completed Mar 24, 2022
@es-romo
Copy link

es-romo commented Sep 22, 2023

@zirkelc I've been dealing with the exact same problem you had for a couple of days now. Do you happen to remember how you got it fixed?

@zirkelc
Copy link
Author

zirkelc commented Sep 22, 2023

I stopped using Lerna for local dependencies and I switched over to serverless-esbuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reply Awaiting for a reply from the OP
Projects
None yet
Development

No branches or pull requests

4 participants